I am updating my site frequently after finishing updates my clients reporting that old images & scripts are getting loaded instead of new ones. I know they are coming from their browser cache but is there any way i can force scripts not to load from cache in server.
I am using nginx with php-fpm.
By default, NGINX Plus caches all responses to requests made with the HTTP GET and HEAD methods the first time such responses are received from a proxied server. As the key (identifier) for a request, NGINX Plus uses the request string.
Go to the “Web Server” tab. In the “nginx settings” section, select the “Enable nginx caching” checkbox. (Optional) You can customize nginx caching settings. If you are not familiar with nginx caching, we recommend that you keep the default settings.
The header module is a core Nginx module, which means it doesn't need to be installed separately to be used. To add the header module, open the default server block Nginx configuration file in vi (here's a short introduction to vi ) or your favorite text editor: sudo vi /etc/nginx/nginx. conf.
You can force HTTP headers to influence the browser caching behavior, however this is probably not a good idea in a production environment where you want caching.
So simply use something like:
expires -1
To force Cache-Control no-cache
header
Check here for more information:
http://wiki.nginx.org/HttpHeadersModule
That being said, I have gotten myself in the habit of just changing image and static files names as I revise them. Perhaps this comes from working with CDN's where this can be incredibly helpful. So say I have static files that I might update often (i.e. they are not part of some specific piece of content). I would name them like:
someimagev1.jpg
someimagev2.jpg
somejs1.js
somejs2.js
etc.
I change values (and links in HTML source) as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With