Registry / devops / hapi-cache-buster

hapi-cache-buster

JSON →
library0.4.0jsnpmunverified

A Hapi.js plugin that automatically appends a cache-busting query parameter (?v=version) to asset URLs (CSS, JS, images) in view templates. Version 0.4.0 is the latest stable release. It reads the version from package.json or accepts a custom version number. Designed for Hapi.js applications using Handlebars or Jade templates. Differentiator: simple integration with no build steps, relies on package.json version.

npm install hapi-cache-buster
INSTALL
IMPORT
SIG · HAPI-CACHE-BUSTER
H
hapi-cache-buster
devopsjavascriptv0.4.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.

plugin
await server.register({ plugin: require('hapi-cache-buster'), options: {} })
server.register(require('hapi-cache-buster'))
Must pass options object even if empty. Plugin expects a register method with options.
version.cache
{{version.cache}}
{{cacheVersion}}
The cache version is available in templates as 'version.cache', not a custom variable name.
require('hapi-cache-buster')
const HapiCacheBuster = require('hapi-cache-buster');
import HapiCacheBuster from 'hapi-cache-buster';
Package is CommonJS only; no ESM export.

Registers the cache buster plugin with Hapi.js, using a custom version. Demonstrates required plugin registration pattern.

const Hapi = require('@hapi/hapi'); const HapiCacheBuster = require('hapi-cache-buster'); async function start() { const server = Hapi.server({ port: 3000 }); await server.register({ plugin: HapiCacheBuster, options: { version: '1.0.0' // or omit to use package.json version } }); // In your template: <link rel="stylesheet" href="css/styles.css{{version.cache}}"> await server.start(); } start();
Debug
Known issues
gotchaPackage uses process.cwd() to find package.json; if server is started from a different directory, it may fail.
fix
Pass version option manually or set cwd before starting Node.
affects: >=0.0.1
deprecatedOnly works with Hapi.js v17+ (uses async await registration).
fix
Update to latest version or use callback registration for older Hapi.
affects: <0.4.0
gotchaTemplate engine must support interpolation of version.cache. Not all engines will escape properly.
fix
Ensure template engine renderer escapes the query string correctly.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'package.json'
process.cwd() does not contain package.json; plugin tries to read it from current working directory.
fix
Pass version option explicitly or run Node from the project root directory.
TypeError: Cannot read properties of undefined (reading 'cache')
version object not added to template context because plugin did not register correctly.
fix
Ensure plugin is registered with server.register({ plugin: HapiCacheBuster, options: {} }) before template rendering.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
hapi-cache-buster — npm install hapi-cache-buster · libregistry