Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
express cache busting - disable the default caching
1. by default express is using etags caching which may not be preferable
2. add nocache middleware
3. disable etags for server
4. disable etags and last modified for static files middleware
const express = require("express");
const nocache = require("nocache");
const server = express();
// ⚠️ __dirname should be your public path
server.use(express.static(__dirname, {
etag: false,
lastModified: false,
setHeaders: res => nocache(null, res, function(){})
server.listen(8888, "");

This comment has been minimized.

Copy link
Owner Author

commented Sep 26, 2019

More about tracing a cache issue:

  • What are your headers in the browser developer console? Windows & Linux: ctrl+shift+i Mac: cmd+alt+i → Network
  • Hard Refresh ctrl+f5, cmd+shift+r
  • Does your static server middleware have caching options? Can you disable or change it?
  • Are you sure your static files path is going to the correct directory? __dirname or path.join(?, ?, ?)
  • Do any browser extensions keep a cache to increase speed?
  • In the developer tools there might be a setting for "Disable cache (While DevTools open)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.