I have caching enabled for specific files in nginx, like this:
location ~* \.(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
What I'd like to do here is to exclude all files matching the pattern i18n-*.js, and as a result, cache all .js files except for the ones starting with i18n.
I tried to do a negative lookup to exclude the pattern, but it doesn't work as excepted because of the non-capturing group:
location ~* \.(?!i18n-.*\.js)(?:css|js)$ {
access_log off;
add_header Cache-Control "no-transform,public,max-age=31536000,s-max-age=31536000";
expires 1y;
}
What's the smart solution here? I'm no regex expert, so a brief explanation would be helpful, too.