4

My server runs multiple websites using VestaCP. Each of those websites have different public html folder and a specific nginx.conf file. (wildcard nginx include)
I'm trying to disable the cache in nginx on a specific file name...

I know how to disable the cache for a specific file but I want to disable the cache in the nginx.conf whenever a file is named "hello.js" (regardless from which site/location it is delivered).

Example:

https://example.com/hi.js = cached  
https://example.com/hello.js = not cached  
https://example.com/test/hello.js = not cached  
https://example.org/index.js = cached  
https://example.org/me/hello.js = not cached  

I know how to disable the cache on 1 specific file in a domain specific snginx.conf but I rather have one rule that disables caching for each file with the name "hello.js".

server {
    listen 443 http2;
    server_name example.com;
    location /hello.js{
        add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
        expires -1;
    }
}

How can I disable the cache for all "hello.js" files (also on other domains hosted on the server)?

( I ask this question because I work with service workers and the service-worker javascript files should not be cached. If service-worker files are cached by the browser, then the new version is never loaded when the cache names are changed.)

Jozzeh
  • 841
  • 10
  • 28
  • Actually, I think the caching policy should be "Cache-Control: no-cache" That way it doesn't have to refetch without any changes. Right? – Nicolai Schmid May 14 '19 at 13:42

0 Answers0