How to disable cache in Xampp and NodeJs Server

How to disable cache in Xampp and NodeJs Server

When developing frontend sometimes i use NodeJs and Xampp as servers. Sometimes Caching of static files becomes a problem such as styles dont update even though the css files are modified. So i needed to disable the caching.

XAMPP Server

xampp

Edit httpd.conf ([xampp folder]/apache/conf/http.conf) file and add following at the end:

# Don't cache html, htm, js, css

<filesMatch "\.(html|htm|js|css)$"> FileETag None <ifModule mod_headers.c> Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" </ifModule>
</filesMatch>
Enter fullscreen mode
Exit fullscreen mode

NodeJS Server

Use nocache module.

pnpm i nocache
Enter fullscreen mode
Exit fullscreen mode
const nocache = require('nocache');
app.use(nocache());
Enter fullscreen mode
Exit fullscreen mode

OR

Use set etag to false

app.set('etag', false);
Enter fullscreen mode
Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *