PostHTML Plugin Link Preload
This plugin sets up preload/prefetch tags and headers.
Before:
...... component...
After:
...... component...
Install
npm i posthtml posthtml-plugin-link-preload
Usage
const fs = ;const posthtml = ;const posthtmlPluginLinkPreload = ;;
Options
- attr: the html attribute name to use (optional, default: data-link-preload)
- addHeader: a function that is called with 2 arguments: headerName, headerValue (optional, default: an empty function)
Attribute values
data-link-preload:
preload
: enable resource preload (default)prefetch
: enable resource prefetch
data-link-preload-type:
header
: does not insert any additional tag. It calls the function "addHeader" with the new header. Some CDN and HTTP server converts this into HTTP2 server push, if used with preload (default)header-nopush
: like 'header' but it adds 'nopush' to the headersmarkup
: adds additional tag at the top of the head tag
Where to use it
These features can be use on these tags with either srv or href tag:
- script
- link with rel stylesheet
- audio
- video
- track
- img
- iframe
- embed
- object
Adding headers
Here is an example using Expressjs:
app