server-push-generator

0.0.2 • Public • Published

Server Push Generator

Generate HTTP/2 Server Push link headers from generated static HTML.

Install

npm add server-push-generator

You can replace npm with yarn if needed

Usage

const spg = require('server-push-generator')

spg({
  cwd: 'path/to/generated/html/files/dir',
  urlTransformer: file => `/${file.replace(/index\.html$/, '')}`, // function to generate url from file path
  contentTransformer: ({html, matches}) => html.replace('x', 'y'), // function to manipulate html string
  backup: false, // default to backup when `contentTransformer` exists
  raw: false, // return object[] in headers instead of string[]
})

/* output
[
  {
    source: '/zh/guide/',
    headers: [
      '</assets/js/3.f9aace0a.js>; rel=prefetch',
      '</assets/js/24.b2ac9cbd.js>; rel=preload; as=script',
    ]
  }
]
*/

Options

All options for globby plus :

  • raw : boolean
    • default to true
    • customize type of returned headers property
  • urlTransformer : function (singleFilePath)
  • contentTransformer: function ({html, matches}),
  • backup: string | boolean

Package Sidebar

Install

npm i server-push-generator

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

7 kB

Total Files

4

Last publish

Collaborators

  • ekoeryanto