When serving large text files, be it .json
, .css
or js
or anything else that is purely text based, they should be served using compression. This could bring enormous network benefits, especially when using slower networks where every byte counts.
Google Page Speed Insights flags this usually when you have large files that are not compressed. It also has a big impact as they throttle their networks to simulate slower speeds.
To set up text compression you could either use an application setup, or an easier alternative is server level text compression.
Look at my caddy text compression configuration to see how I enabled it for mathieu.deraedt.dev
.
Popular algorithms and well supported by the browser are zstd, Gzip and brotli.
Small files
Both encoding and decoding requires resources. If the files are too small, these compression might actually not be beneficial. Doubly so when they’re encoded on the fly.