
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@mightyplow/eleventy-plugin-cache-buster
Advanced tools
A plugin for @11ty/eleventy to add hashes to used resources.
A plugin for eleventy which adds a unique query parameter to css and js resources. This allows to set unlimited caching for those resources and ensure that they get properly reloaded when they change. See this article on Cache Busting.
By default the hash is created out of the resource content (see notes).
npm i @mightyplow/eleventy-plugin-cache-buster -D
In your projects' .eleventy.js file, add the plugin.
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
module.exports = function(eleventyConfig) {
const cacheBusterOptions = {};
eleventyConfig.addPlugin(cacheBuster(cacheBusterOptions));
};
The directory where eleventy stores the built files to. This is required to resolve resources which start with a slash. If eleventy is called with the --output option from the command line, this option can be omitted.
The query parameter which is appended to the resource urls, i.e. /foo/bar.css?v=[hash].
An object which maps the relevant html tags to the attributes, in which the url can be found in. By default it is looking for script tags and link tags.
Since the options get merged, the default attributes don't have to be included when you want to add additional ones.
The function which creates the hash for the found urls. You can use that if you want to add a custom value.
By default an MD5 hash is created out of the file content. Therefore the assets have to be built before running eleventy (see notes). If you want to build everything in parallel you can for instance add a timestamp. Notice that then the cache busting parameter changes on every build which leads to resources being cache busted with every release.
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
module.exports = function(eleventyConfig) {
const cacheBusterOptions = {
createResourceHash(outputDirectoy, url, target) {
return Date.now();
}
};
eleventyConfig.addPlugin(cacheBuster(cacheBusterOptions));
};
By now this plugin only works with path-relative URLs.
what will get processed:
/assets/css/foo.css
../assets/css/foo.css
what will not get processed:
//foo.bar/assets/css/foo.css
https://foo.bar/assets/css/foo.css
In order to create the resource hashes, the resource files have to be built before the html. You have to ensure this in your build process.
FAQs
A plugin for @11ty/eleventy to add hashes to used resources.
We found that @mightyplow/eleventy-plugin-cache-buster demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.