Generate HTTP2 Server Push headers for Netlify using HtmlWebpackPlugin
npm install netlify-push-webpack-pluginGenerate HTTP2 Server Push _headers file for Netlify using HtmlWebpackPlugin.
For use with Webpack 4 and HtmlWebpackPlugin 4
```
npm i netlify-push-webpack-plugin
or
``
yarn add netlify-push-webpack-plugin
| Option | Type | Description |
| ---------- | ------ | -------------------------------------------------- |
| filename | String | Name and path of the generated headers file |headers
| | Array | Other headers to be added to the file (optional) |include
| | String | Only include 'css', 'js' or 'all' (default: 'all') |
The following config
`js
const HtmlWebpackPlugin = require("html-webpack-plugin");
const NetlifyServerPushPlugin = require("netlify-push-webpack-plugin");
module.exports = {
plugins: [
new HtmlWebpackPlugin(),
new NetlifyServerPushPlugin({
filename: "_headers",
headers: [
" X-Frame-Options: DENY",
" Referrer-Policy: strict-origin-when-cross-origin",
"/assets/*",
" Cache-Control: public, max-age:360000"
],
include: "css"
})
]
};
`
will result in a headers file looking something like this:
``
/*
Link:
Link:
X-Frame-Options: DENY
Referrer-Policy: strict-origin-when-cross-origin
/assets/*
Cache-Control: public, max-age:360000
Tests are ran using using Ava with the following command:
```
npm run test