Configuring nginx to prevent browsers caching your files

Tom Szpytman
Aug 30 · 1 min read

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;

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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