Selective .js cache on nginx

bazaglia asked:

I have one .js file that can’t be cached by the browser. Because of this file, I have this in my nginx configuration file:

location ~* .(js)$ {
expires epoch; log_not_found off; access_log off;

However, this is terrible: because of one file, all the others .js files don’t be cached by the browser. There are .js files in subdomains that may be cached. So, here’s what I can do:

• Disallow all .js my files on my main public folder be cached and let all my files on subfolders be cached.

How can I make this configuration in nginx?


My answer:

location = /dont/cache/this.js {
    expires epoch;

location ~* \.js$ {
    expires max;

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.