Generate compressed assets and files for your Jekyll site at build time using Brotli compression.
Performance in web applications is important. You know that, which is why you have created a static site using Jekyll. But you want a bit more performance. You're serving your assets and files gzipped, but could it be better?
Google's Brotli compressor is a new format with better compression than Zlib's gzip or Zopfli and is supported in all major modern browsers. Compressing files at build time means you can use the highest compression levels with no penalty for dynamically generating the files, so if you're building your site with Jekyll, why not generate the files at the same time?
Add this line to your application's Gemfile:
And then execute:
Once you have the gem installed, run
JEKYLL_ENV=production bundle exec jekyll build. In your destination directory (
_site by default) you will find brotli files.
Jekyll::Brotli only runs when the environment variable
JEKYLL_ENV is set to
production as dealing with compressing files is unnecessary in development mode and just slows down the site build.
Serving pre-compiled gzip files
You will likely need to adjust your web server config to serve these precomputed gzip files. See below for common server configurations:
For nginx, you need to compile nginx with Google's
ngx_brotli module. Follow the steps in this blog post for more detail.
Other web servers
TODO: instructions for other web servers like Apache, HAProxy, etc.
After checking out the repo, run
bundle install to install dependencies. Then, run
bundle exec rspec to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/philnash/jekyll-brotli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Jekyll::Brotli project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.