Registry / devops / cache-busted

cache-busted

JSON →
library1.2.0jsnpmunverified

Express middleware for cache busting static assets by appending a version query string. Uses the package version from package.json in production/integration, and appends a timestamp in development to force reloads. Stable version 1.2.0. Minimal configuration—attach to the app via handler() and use cacheBust() in templates. Differentiators: zero-config version detection, automatic dev vs prod behavior, and support for custom version or package path.

npm install cache-busted
INSTALL
IMPORT
SIG · CACHE-BUSTED
C
cache-busted
devopsjavascriptv1.2.0
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.

cacheBust
const cacheBust = require('cache-busted')
import cacheBust from 'cache-busted'
Package is CJS only; no default ESM export. Use require() in Node.
handler
const cacheBust = require('cache-busted'); cacheBust.handler(app, options)
require('cache-busted').handler(app) // correct but missing variable
Must call handler() once to expose cacheBust in app.locals. Options are optional.
cacheBust (template helper)
app.locals.cacheBust('/path/to/file.js')
cacheBust('/path') // not available globally
Only available after handler() is called, accessed via app.locals in templates.

Shows initialization and usage of cache-bust with Express, including how to call handler and use cacheBust in templates.

const express = require('express'); const cacheBust = require('cache-busted'); const app = express(); // Initialize cache busting cacheBust.handler(app, { version: '1.0.0' }); // optional version // In your template (e.g., Pug/Handlebars): // link(href=cacheBust('/css/style.css') rel='stylesheet') // In Jade: != cacheBust('/css/style.css') // For a full example, see README. app.get('/', (req, res) => { res.send('Cache busting active'); }); app.listen(3000);
Debug
Known issues
gotchacacheBust() function only available in templates after handler() call. Forgetting to call handler results in 'cacheBust is not a function'.
fix
Ensure cacheBust.handler(app) is called before rendering any template that uses cacheBust().
affects: >=0.0.0
breakingIn NODE_ENV other than 'production' or 'integration', cacheBust appends a timestamp causing every request to bust cache. Unexpected in custom environments.
fix
Set NODE_ENV to 'production' or 'integration' for stable version-based caching, or explicitly pass a version option.
affects: >=0.0.0
gotchapackage.json location defaults to ../../package.json relative to the module. If your layout differs, version may be undefined, and cacheBust returns '/path?v=undefined'.
fix
Set options.packageLocation to the correct path or options.version to a specific version string.
affects: >=0.0.0
deprecatedThe module has not been updated since 2015. No support for modern ES modules or TypeScript. Consider alternatives like webpack chunk hashing.
fix
Use a build tool (Webpack, Vite) for cache busting via content hashes instead of this middleware.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cacheBust.handler is not a function
Incorrect import (trying ES import on CJS module) or missing require.
fix
Use const cacheBust = require('cache-busted'); then cacheBust.handler(app);
Cannot read property 'version' of undefined
package.json not found at default location, so version is undefined.
fix
Pass options.version or set options.packageLocation to correct path.
ReferenceError: cacheBust is not defined
cacheBust() called in template before handler() was invoked.
fix
Ensure app is passed to cacheBust.handler(app) before rendering.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
cache-busted — npm install cache-busted · libregistry