Skip to content

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

License

Notifications You must be signed in to change notification settings

ekoeryanto/server-push-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published