I am trying to tell nginx to cache some of my assets (js, css) forever, or at least for a very long time.
The idea is that as soon as the asset package is compiled and published with the URI prefix /assets/(for example /assets/foo-{fingerprint}.js), it remains there and does not need to be changed.
The internet told me that I should write the following rule:
location ~ ^/assets/.*-([^.]+)\.(js|css)$ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
I expect this to lead to responses with HTTP code 304 "Not Modified", but I get a consistent HTTP 200 (OK) every time.
I tried some other approaches, for example:
a) by explicitly setting the modification time to a constant point in time in the past;
add_header Last-Modified "Thu, 01 Jan 1970 00:00:00 GMT";
b) transition to verification If-None-Match;
add_header ETag $1;
if_modified_since off;
, , :
add_header Last-Modified "Thu, 01 Jan 2030 00:00:00 GMT";
if_modified_since before;
. , . , .