Configuring nginx to prevent browsers caching your files

Tools like create-react-app come pre-configured to change the file names of the JavaScript bundles they output, but what about the index.html files that are also outputted?

If not configured otherwise, browsers will cache your index.html files, and I’ve found this may lead to problems where cached index files point to obsolete, or worse still, non-existent JavaScript files.

If you use nginx, you can use the following snippet to circumvent this (and force browsers to fetch a new copy of your index.html on every request):

location / {
add_header Cache-Control 'no-store';
add_header Cache-Control 'no-cache';
expires 0;

Written by

Full-stack + Product. Available for hire either as an independent contractor, or as part of a team. Inquiries: mail [at]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store