Improve first load weight? #9330
Replies: 7 comments 7 replies
-
I'd definitely be interested in slimming down HTML pages if there's room for the Quarto team to do so without compromising functionality. For our interactives at https://github.com/360-info, I generally use CSS and JS assets are usually the smaller part of page load for our interactives (the datasets are usually on the order of 100s of KB or maybe low MBs), but at least we can set up the page if we have the CSS and JS, even if the data is still incoming. (And I admit that there's plenty I could still do to improve the load of our interactives too!) I don't know whether there's a significant benefit to minifying code on top of server-side compression (although I guess gzip has to at least represent white space with some RLE, so there's probably at least a tiny bit), but I'd be interested to see data on it! I would be happy to use a |
Beta Was this translation helpful? Give feedback.
-
Those are dependencies for the search feature. You can disable through config. See https://quarto.org/docs/websites/website-search.html#disabling-search
This would be a first good way to start on this. This should reduce the size a lot. @CharlesNepote did you set that option before doing your sizing ? It would be interesting to see the difference if not. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your answers @jimjam-slam and @cderv. I have built the following bash script, here are my results with
#!/bin/bash
# purge_css.sh
echo "$(date +'%Y-%m-%dT%H:%M:%S') - $0 - CSS purge and minification..."
# See: https://purgecss.com/CLI.html
# sudo npm i -g purgecss
mkdir -p ./temp_purgecss
find ./_site -type f -name "*.css" \
-exec echo {} \; \
-exec purgecss --css {} --content "./_site/**/*.js" "./_site/**/*.html" -o ./temp_purgecss \; \
-exec bash -c ' mv "./temp_purgecss/`basename {}`" "`dirname {}`" ' \;
rmdir ./temp_purgecss
# See: https://github.com/mishoo/UglifyJS
# sudo npm install uglifyjs -g
# minification of JS files
find ./_site -type f \
-name "*.js" ! -name "*.min.*" ! -name "vfs_fonts*" \
-exec echo {} \; \
-exec uglifyjs -o {}.min {} \; \
-exec rm {} \; \
-exec mv {}.min {} \;
# sudo npm install uglifycss -g
# minification of CSS files
find ./_site -type f \
-name "*.css" ! -name "*.min.*" \
-exec echo {} \; \
-exec uglifycss --output {}.min {} \; \
-exec rm {} \; \
-exec mv {}.min {} \;
echo "$(date +'%Y-%m-%dT%H:%M:%S') - $0 - End." It's quite fast, ~ 5 seconds. Here's the log: ./purge_css.sh
2024-04-14T19:54:23 - ./purge_css.sh - CSS purge and minification...
./_site/site_libs/quarto-html/tippy.css
./_site/site_libs/quarto-html/quarto-syntax-highlighting.css
./_site/site_libs/bootstrap/bootstrap-icons.css
./_site/site_libs/bootstrap/bootstrap.min.css
./_site/styles.css
./_site/site_libs/quarto-nav/quarto-nav.js
./_site/site_libs/quarto-search/autocomplete.umd.js
./_site/site_libs/quarto-search/quarto-search.js
./_site/site_libs/quarto-html/quarto.js
./_site/site_libs/quarto-listing/quarto-listing.js
./_site/site_libs/quarto-html/tippy.css
./_site/site_libs/quarto-html/quarto-syntax-highlighting.css
./_site/site_libs/bootstrap/bootstrap-icons.css
./_site/styles.css
2024-04-14T19:54:27 - ./purge_css.sh - End. This solution needs to install I have tried to build a typescript script but failed to import libraries with deno. |
Beta Was this translation helpful? Give feedback.
-
@jimjam-slam could you give examples (you have so many repos!)?
@cderv In fact I would love to keep this feature, but I was wondering if this js stuff could be loaded on the user demand: eg. clicking on the search icon would load the scripts. |
Beta Was this translation helpful? Give feedback.
-
I guess the majority of the users are rarely using the search engine, if ever. This one is currently always loaded: By the way, it seems possible to launch the search engine on demand (using events such as I'll try to investigate further. |
Beta Was this translation helpful? Give feedback.
-
I suspect it's a different topic albeit related, but I have been getting in trouble with my front page listing being >100MB. I've opened a discussion about that under #9390 |
Beta Was this translation helpful? Give feedback.
-
While we're talking about optimization: is it possible to include asset bundling in quarto? This could make this tool more effective for generating static websites. Instead of importing potentially dozens of site_libs, one could just include the bundle... |
Beta Was this translation helpful? Give feedback.
-
Description
Quarto could be an awesome tool to generate low-tech static websites (example), in particular for not-so-techies people.
There is, however, an important obstacle: Quarto's simple HTML page first load weights ~1MB.
I have done a first simple test using PurgeCSS, adapting this code: web page weight is reduced from 960 KB to 498 KB. Bootstrap CSS file is reduced from 463 KB to 93 KB.
Minifying reduced from 498 KB to 470 KB.
Also, ~125 KB are taken for the (useful!) search feature (
quarto-search.js
andautocomplete.umd.js
), while many users don't use it at all.Wouldn't it be possible to call those script on demand?
Last, ~30 KB is also taken by Google Fonts even if I specify
mainfont
andmonofont
:With a well configured web server, all these files can be compressed on the fly (~220 KB) and also cached on the browser. But it is still a certain amount of bytes. Not all the web clients are accepting gziped content encoding, and many people only visit one page. What could be the possibilities to lower page weight?
I understand I can launch
post-render
command lines or scripts, but I think it is not ideal.Maybe I'm asking too much, and my need doesn't interest many people. I just think that digital is one of the few places where you can significantly, easily and quickly reduce your footprint on the planet compared to physical stuff.
See also
minimal
option, and a working example #9305Beta Was this translation helpful? Give feedback.
All reactions