Static site serves html, css, javascript and images. These files can be compressed to reduce bandwidth.
<!-- more -->
# Minify
[Minify](https://en.wikipedia.org/wiki/Minification_(programming)) html, css and js to remove characters that are not required for the code to function. This process involves removing white space/tab, line break and comments. I read somewhere that Google saves gigabytes of bandwidth just by removing line break, which surprised me how much line break alone costs when you have the popularity of Google.com.
1. The easiest way is using hexo-all-minifier. Unlike others, this plugin also compress images as well. To use it, simply run the following command in your hexo folder:
To see this in action, check out this [job log](https://gitlab.com/curben/blog/-/jobs/101703188). As you can see, the resulting files are around 20% smaller. However, do note that its image compression dependencies have some [vulnerabilities](https://snyk.io/test/npm/hexo-all-minifier). This can be patched using [Snyk](https://snyk.io/).
Despite the convenience of hexo-all-minifier, I don't use it due to the vulnerability. I don't need its image compression since the [Cloudinary](https://cloudinary.com/) image hosting offers [auto compression](https://cloudinary.com/documentation/responsive_images#responsive_images_with_automatic_quality_selection).
[Compression](https://en.wikipedia.org/wiki/Data_compression) uses more advanced technique to reduce the file size even further. Most modern web browsers support gzip decompression and prefer it (with appropriate HTTP header). As you might know from zipping a text file, this can yield significant reduction in file size. For example, my home page `index.html` is less than half smaller (3.3KB > 1.2KB). Check it out [here](https://gitlab.com/curben/blog/-/jobs/101703188/artifacts/browse/public/).
***Update:*** hexo-yam 0.5.0+ offers gzip and brotli compressions. After you install it, it will automatically compress assets files to `.gz` and `.br` whenever hexo generate/deploy/server. This means the command `$ find ....` as shown below is no longer required.