Skip to content
SRI support for Handlebars
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
bower.json
index.js
package.json

README.md

handlebars-helper-sri Build Status

Install

npm install --save handlebars-helper-sri

Usage

Attach the helper to handlebars:

var handlebars = require("handlebars");

handlebars = require("handlebars-helper-sri").register(handlebars);

Then, call the helper from your Handlebars template:

<script src="/script.js" integrity="{{sri "./public/script.js"}}"></script>
<link href="/style.css" integrity="{{sri "./public/style.css"}}" rel="stylesheet">

You may also select custom properties from subresource:

<!-- select subresource("./public/script.js")["hashes"]["sha256"] -->
<script src="/script.js?{{sri "./public/script.js" "hashes" "sha256"}}"></script>

Caching

You may wish to attach a custom subresource instance, for pre-load caching:

var handlebars = require("handlebars");
var subresource = require("subresource");

[
    "../public/script.js",
    "../public/style.css"
].forEach(subresource);

handlebars = require("handlebars-helper-sri").register(handlebars, subresource);

Warning: The first instance attachment will persist as long as node is running (even if you require("handlebars") again). Handlebars.registerHelper appears to mutate the require cache (potential Node bug). As such, you can only ever use one instance of Handlebars.

You can’t perform that action at this time.