0.01
Low commit activity in last 3 years
No release in over a year
Generate brotli compressed assets and files for your Jekyll site at build time.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.16, < 3.0
~> 13.0
~> 3.0
~> 0.15.1

Runtime

~> 0.2.0
>= 3.0, < 5.0
 Project Readme

Jekyll::Brotli

Generate compressed assets and files for your Jekyll site at build time using Brotli compression.

Gem Version Build status Maintainability Inline docs

API docs | GitHub repo

Why?

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?

Jekyll::Brotli does just that. Add the gem to your Jekyll application and when you build your site it will generate brotli files for all text based files (HTML, CSS, JavaScript, etc).

Warning

Brotli is not supported everywhere, so you may want to also gzip your files too. Check out Jekyll::Gzip and Jekyll::Zopfli for options there.

Installation

Add this line to your application's Gemfile:

gem 'jekyll-brotli'

And then execute:

bundle install

Usage

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.

Configuration

Extensions

By default, Jekyll::Brotli will compress all files with the following extensions:

  • '.html'
  • '.css'
  • '.js'
  • '.json'
  • '.txt'
  • '.ttf'
  • '.atom'
  • '.stl'
  • '.xml'
  • '.svg'
  • '.eot'

You can supply your own extensions by adding a brotli key to your site's _config.yml listing the extensions that you want to compress. For example to only compress HTML, CSS and JavaScript files, add the following to _config.yml:

brotli:
  extensions:
    - '.html'
    - '.css'
    - '.js

Compression quality

By default, Jekyll::Brotli uses the maximum compression quality supported by Brotli, which is 11. You can supply your own compression quality by setting a number between 0 and 11 on _config.yml.

brotli:
  quality: 9

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:

nginx

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.

Do you know how to do this for a different server? Please open a pull request or an issue with the details!

Development

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.

Contributing

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.

License

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.