Metalsmith plugin compressing files using brotli.
JavaScript
Permalink
Failed to load latest commit information.
lib
test
.eslintrc
.gitignore Initial commit. Sep 3, 2014
.npmignore
.travis.yml Install g++ on travis-ci Jul 23, 2016
LICENSE First version using brotli instead of gzip Jul 23, 2016
README.md
package.json First version using brotli instead of gzip Jul 23, 2016

README.md

metalsmith-brotli Build Status npm

A Metalsmith plugin that creates compressed copies of the site's content using the Brotli algorithm. This is useful if you want to pre-compress static files and serve them via the nginx brotli static module (ngx_brotli), for example.

Installation

$ npm install metalsmith-brotli

Usage

var Metalsmith = require("metalsmith");
var brotli = require("metalsmith-brotli");

var metalsmith = new Metalsmith(__dirname)
  .use(brotli());

metalsmith-brotli will compress a file if the extension matches this regular expression:

/\.[html|css|js|json|xml|svg|txt]/

The choice of files to compress is loosely based on the HTML5 Boilerplate server configuration.

The plugin compresses each matching file. Depending on the overwrite options (see below) the plugin either replaces the original file or creates a new one with the .br extension.

Customization

Pass an options object to customize metalsmith-brotli's behaviour. These are the available options keys:

src is a multimatch pattern which specifies which types of files to compress.

var metalsmith = new Metalsmith(__dirname)
  .use(compress({
    src: ['**/*.js', '**/*.css'] // only compress JavaScript and CSS
  }));

brotli is the same configuration object accepted by iltorb.compress. For example, you can set the compression level as follows:

var metalsmith = new Metalsmith(__dirname)
  .use(compress({
    src: ['**/*.js', '**/*.css'],
    brotli: {
      quality: 11
    }
}));

Add overwrite: true to replace files with the compressed version instead of creating a copy with the .br extension:

var metalsmith = new Metalsmith(__dirname)
  .use(compress({
    overwrite: true
  });

Deployment

You need to create a script to upload the compressed versions of the files to your preferred hosting provider yourself. Take care to serve the files with the correct Content-Encoding.

Acknowledgements

This plugin is based on metalsmith-gzip by Ludovico Fischer, licensed under the MIT License.

License

metalsmith-brotli is released under the MIT license. See the LICENSE file for more information.