Gatsby plugin for preparing brotli-compressed versions of assets.
/webpack-runtime-cde5506958f1afc4d89e.js
becomes
/webpack-runtime-cde5506958f1afc4d89e.js.br
This plugin will only generate the compressed files. To see them been served to the client, your Gatsby website should run on a production server that supports Brotli .br-files. The Gatsby development server does not serve the compressed versions.
With npm:
npm install --save gatsby-plugin-brotli
Or with Yarn:
yarn add gatsby-plugin-brotli
In your gatsby-config.js
file add:
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-brotli'
}
]
}
By default, only .css
and .js
files are compressed, but you can override this with the extensions
option.
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-brotli',
options: {
extensions: ['css', 'html', 'js', 'svg']
}
}
]
}
By default, files are compressed using the highest level of compression supported by brotli, but you can override this with the level
option.
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-brotli',
options: {
level: 4
}
}
]
}
You can even place all the brotli-compressed files (only the brotli ones, the uncompressed ones will
be saved in the public
directory as usual) in a dedicated directory (ex. public/brotli
):
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-brotli',
options: {
path: 'brotli'
}
}
]
}
If you would like to help out with some code, check the details.
Not a coder, but still want to support? Have a look at the options available to donate.
Licensed under MIT.
NOTE: This plugin only generates output when run in production
mode! To test, run: gatsby build && gatsby serve