connect-cachify
raw JSON → 0.0.17 verified Sat Apr 25 auth: no javascript deprecated
Connect/Express middleware for browser cache optimization via asset fingerprinting and concatenation. Current version 0.0.17 (unmaintained). Provides `cachify.setup` middleware and view helpers (`cachify_js`, `cachify_css`) that rewrite asset URLs to include a content hash, allowing far-future Expires headers and transparent fallback to individual scripts in development. Unlike connect-assets, it focuses solely on HTTP caching headers and URL rewriting without compilation. No release cadence; last published in 2013. Node.js >=0.4.7 required.
Common errors
error Error: Cannot find module 'connect-cachify' ↓
cause Package not installed or missing from node_modules.
fix
Run
npm install connect-cachify and ensure it's in your package.json dependencies. error TypeError: cachify.setup is not a function ↓
cause Importing the module incorrectly (e.g., using default import when CommonJS required).
fix
Use
const cachify = require('connect-cachify'); and then cachify.setup(...). error ReferenceError: cachify_js is not defined ↓
cause View helper not available in template because middleware hasn't been applied or locals not set.
fix
Ensure
app.use(cachify.setup(...)) is called before any route that renders templates, and that res.locals.cachify_js is set. Warnings
deprecated Package has not been updated since 2013 and is incompatible with modern Express 4+ middleware pattern (no error middleware, deprecated `res.redirect` calls). ↓
fix Migrate to express-cachebuster or custom middleware with `etag` and `last-modified` handling.
breaking The `cachify.setup` middleware must be placed before `express.static` or other response-sending middleware, otherwise assets will be served without fingerprinting. ↓
fix Ensure `app.use(cachify.setup(...))` is called before `app.use(express.static(...))`.
gotcha View helpers `cachify_js` and `cachify_css` are attached to `req` and `res` objects, not `app.locals`. In Express 4, you must manually pass them to templates via `res.locals`. ↓
fix Use middleware: `app.use(function(req, res, next) { res.locals.cachify_js = req.cachify_js; res.locals.cachify_css = req.cachify_css; next(); });`
deprecated The `url_to_paths` option uses absolute filesystem paths; in production, use relative paths to avoid portability issues. ↓
fix Set `root` option and use relative paths in assets map instead of `url_to_paths`.
Install
npm install connect-cachify yarn add connect-cachify pnpm add connect-cachify Imports
- default wrong
const { setup } = require('connect-cachify')correctimport cachify from 'connect-cachify' - setup wrong
import setup from 'connect-cachify/setup';correctconst { setup } = require('connect-cachify'); - cachify_js wrong
import { cachify_js } from 'connect-cachify';correctapp.locals.cachify_js = require('connect-cachify').cachify_js;
Quickstart
const express = require('express');
const cachify = require('connect-cachify');
const app = express();
const assets = {
'/js/bundle.min.js': ['/js/a.js', '/js/b.js']
};
app.use(cachify.setup(assets, {
root: __dirname + '/public',
production: process.env.NODE_ENV === 'production'
}));
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');
app.get('/', function(req, res) {
res.render('index', { cachify_js: req.cachify_js, cachify_css: req.cachify_css });
});
app.listen(3000);