Registry / devops / grunt-cache-busting

grunt-cache-busting

JSON →
library0.0.11jsnpmunverified

A Grunt 0.4 plugin for cache busting static files by renaming files with a content hash and updating references in HTML. Version 0.0.11 is the latest and appears stable though rarely updated. It differs from alternatives like grunt-cache-bust by supporting both filename-embedded hashes and query string parameters, and it also cleans up old hashed files. It requires Grunt ~0.4.0 as a peer dependency and operates in a Node environment >= 0.8.0.

npm install grunt-cache-busting
INSTALL
IMPORT
SIG · GRUNT-CACHE-BUSTIN
G
grunt-cache-busting
devopsjavascriptv0.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

grunt-cache-busting task
grunt.loadNpmTasks('grunt-cache-busting');
require('grunt-cache-busting');
Grunt plugins are loaded via loadNpmTasks, not directly required. The task is then configured in the Gruntfile under the 'cache-busting' key.
cache-busting task configuration
grunt.initConfig({ 'cache-busting': { /* target options */ } });
grunt.initConfig({ cache_busting: {} });
The task name uses a hyphen, not underscore. The configuration key must be quoted if it contains a hyphen, or accessed via bracket notation.
grunt task alias
grunt.registerTask('default', ['cache-busting']);
grunt.registerTask('default', ['cache_busting']);
When registering tasks, use the hyphenated name 'cache-busting', not underscore.

Minimal Gruntfile configuring the cache-busting task for CSS files. The task renames style.css to include a content hash, updates all HTML references, and cleans up old hashed files.

// Gruntfile.js module.exports = function(grunt) { grunt.loadNpmTasks('grunt-cache-busting'); grunt.initConfig({ 'cache-busting': { css: { replace: ['tmp/**/*.html'], replacement: 'style.css', file: 'tmp/deploy/css/style.css', cleanup: true } } }); grunt.registerTask('default', ['cache-busting']); };
Debug
Known issues
deprecatedgrunt-cache-busting is no longer under active development. Last release was in 2015 and remains compatible only with Grunt 0.4.
fix
Consider migrating to a modern alternative such as gulp-cache-bust or webpack's content hash.
affects: 0.0.11
gotchaThe 'replacement' string must exactly match the reference in the replaced files, including extension. If the extension is omitted, the hash will be appended directly without extension preservation.
fix
Ensure replacement includes the full filename with extension (e.g., 'style.css'). For requirejs, provide the base name without extension (e.g., 'MainApp').
affects: *
gotchaThe 'file' option points to the original file that will be renamed. The task will fail if the file does not exist or if the directory is not writable.
fix
Verify that the file path in 'file' is correct and that the file exists before running the task.
affects: *
gotchaUsing 'get_param: true' appends a query string ?v=HASH. Some proxy servers will not cache-bust on query string changes; consider using filename hashing instead.
fix
For reliable cache busting, omit get_param or set it to false, so the filename is changed.
affects: *
Errors
Common errors & fixes
Warning: Task "cache-busting" not found. Use --force to continue.
The grunt-cache-busting plugin is not installed or not loaded in Gruntfile.
fix
Run 'npm install grunt-cache-busting --save-dev' and add 'grunt.loadNpmTasks('grunt-cache-busting');' to your Gruntfile.
Fatal error: Unable to read file "path/to/file" (Error code: ENOENT).
The file specified in the 'file' option does not exist.
fix
Check that the file path is correct and the file exists before running the task.
ReferenceError: Replace option 'replacement' not defined.
The 'replacement' option is missing from the task configuration.
fix
Add a 'replacement' string to your cache-busting target, e.g., replacement: 'style.css'.
ReferenceError: Replace option 'file' not defined.
The 'file' option is missing from the task configuration.
fix
Add a 'file' string pointing to the file to be hashed, e.g., file: 'dist/css/style.css'.
Warning: Path must be a string. Received undefined
The 'replace' option is not set or is an invalid type.
fix
Ensure 'replace' is an array of glob patterns, e.g., replace: ['src/**/*.html'].
Upgrade
Version history
0.0.11latest on npm
Audit
Dependencies
gruntrequiredrequired peer dependency, version ~0.4.0
Agent activity
8 hits · last 30 days
node
8
Resources
grunt-cache-busting — npm install grunt-cache-busting · libregistry