Adding an NGINX location block for cache exception, but it's giving me a 404 error.

I have a file called loader.js that I don’t want to cache. So, below is the block of code I have implemented. This is on Django-One-Click app.

# to prevent the caching of loader.js
location ~* loader\.js$ {
    add_header Cache-Control "no-store";

I ran sudo nginx -t, it came out successful and restarted nginx. But, once I add the block, loader.js becomes 404. What am I doing wrong?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Location still need to return the file itself.

location ~* loader\.js$ {
    add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    if_modified_since off;
    expires off;
    root /your/site/folder/with/this/file/;

This will serve /loader.js, /whatever/loader.js so be careful. If you call loader always from root, you can use location = /loader.js