Nginx does not refresh file after repeated changing. Old Last Modified header is returned

房东的猫 提交于 2019-12-05 12:43:38

There is not enough information to determine the root cause of the problem that's being experienced; I also imagine that all new folks that come to this question experience a slightly different problem that the one outlined above.

Nginx has http://nginx.org/r/if_modified_since directive, you can take a look at the source code of the implementation in ngx_http_not_modified_filter_module.c :: ngx_http_not_modified_header_filter().

In general, just because the URL has a changed epoch parameter (the ? part with the UNIX time as a trailing slug), doesn't at all mean that a new resource has to be provided, so, to determine that nginx is wrong simply because the URL is different between the first two pics, yet Last-Modified time is same, is not correct. Likewise, the final third pic lists a 304 Not Modified response, yet there is no information about the If-Modified-Since nor If-None-Match headers in the response, and the attribution for the pic doesn't make any sense, either.

Based on my experience this is probably not a nginx-issue but a common browser-behavior.

Browsers might refresh the page itself if you force it, but file-links are not always populated and the files are served from the cache.
If I have to change files like images, stylesheets or script-files several times I open an extra tab, for the corresponding file and populate there first before the page which includes that file.

If you've server access, which has to be assumed as you mention nginx, it's possible to reduce the max-age to a few seconds only or set a no-cache-header for a file. Then browser will always serve the newest version.

Change your nginx config to reduce the expiration. You see that the difference between Expires and Last-Modified is 10 days, as reflected in the config file.

location ~* ^.+\.(jpg|jpeg|svg|gif|png)$ {
   expires 1M;     
   try_files $uri @app;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!