nginx caches JS for one hour, as follows
location ~ .*\.(js|css)?$ {
expires 1h;
}
OK, this is no problem. I want to refresh the cache temporarily. At worst, I can just add a suffix, for example: abc.js?v=123
Now that I have debugged online, I want to remove the suffix and restore abc.js?v=123
to abc.js
, but it is still cached at this time. , how to break it?
習慣沉默2017-05-16 17:26:48
Your rule above just adds an expiration rule to the header
Tell the browser that this thing expires in 1 hour
It’s not that nginx caches it
黄舟2017-05-16 17:26:48
This cache refers to the cache of your browser (client, not nginx). Under normal circumstances, Ctrl+R
forced refresh will remove the cache.
Or clear your browser cache and it will be OK.
仅有的幸福2017-05-16 17:26:48
grunt-rev
Use the rev task together with yeoman/grunt-usemin for cache busting of static files in your app. This allows them to be cached forever by the browser.
This way, nginx header settings will never expire.
怪我咯2017-05-16 17:26:48
Using fis, the best front-end solution in the Eastern Hemisphere, we have a dedicated set of solutions.
fis
仅有的幸福2017-05-16 17:26:48
http://labs.frickle.com/nginx_ngx_cache_purge/README
http {
proxy_cache_path /tmp/cache keys_zone=tmpcache:10m;
server {
location / {
proxy_pass http://127.0.0.1:8000;
proxy_cache tmpcache;
proxy_cache_key $uri$is_args$args;
}
location ~ /purge(/.*) {
allow 127.0.0.1;
deny all;
proxy_cache_purge tmpcache $is_args$args;
}
}
}
Visit 127.0.0.1/purge/abc.js to delete cached files.
Add the parameter --add-module=/path/to/ngx_cache_purge when configuring to add this third-party purge module.
过去多啦不再A梦2017-05-16 17:26:48
Similar to expires
max-age
e-tag
These header information are cache headers for front-end browsers. For example, if you just set expires for one hour, then the browser will not request the file again one hour after the request is completed. To communicate with the server, local cache files are used every time. Within this hour, only the browser clears the cache or disables the cache in the developer tools to communicate with the server. Otherwise, any changes to the file on the server within this hour will have no impact on the browser. .