A Metalsmith plugin to compress build files with brotli.
Last updated 2 months ago by michel-kraemer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metalsmith-brotli 
SYNC missed versions from official npm registry.

metalsmith-brotli Node.js CI 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.


$ npm install metalsmith-brotli


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

let metalsmith = new Metalsmith(__dirname)

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


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.


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.

let metalsmith = new Metalsmith(__dirname)
    src: ["**/*.js", "**/*.css"] // only compress JavaScript and CSS

options is of type BrotliOptions. For example, you can set the compression level as follows:

const zlib = require("zlib");

let metalsmith = new Metalsmith(__dirname)
    src: ["**/*.js", "**/*.css"],
    options: {
      params: {
        [zlib.constants.BROTLI_PARAM_QUALITY]: 11

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

let metalsmith = new Metalsmith(__dirname)
    overwrite: true


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.


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


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

Current Tags

  • 2.0.0                                ...           latest (2 months ago)

6 Versions

  • 2.0.0                                ...           2 months ago
  • 1.4.0                                ...           2 months ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 7
Dependencies (2)
Dev Dependencies (2)
Dependents (0)

Copyright 2014 - 2016 © |