.htaccess: Cache Control, how can I handle website updates?

I just searched the Internet, but could not find a good answer to this question:

The Google Page Speed ​​Extension for FF told me to cache files on my website (PHP). So I updated my .htaccess(in my beta area of ​​the website) to cache certain file types:

ExpiresActive On
ExpiresDefault A0
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>

When encoding in beta, I noticed that due to cache management settings I need to click F5to get the latest .css file, for example. This is not bad for me ... however, what about users?

Can I tell the browser to reload all the files (only) when I update my site (or the file expires) and use the cache if not?

It would be ideal if I could tell the browser: "Hey, all the files before the update time are out of date, please reload them, however the files after the update time are fine, use the cache."

+3
source share
2 answers

Here is a simple approach that I sometimes use that does not require any configuration of complications.

Whenever you modify a css or javascript file, just add a stub parameter to the markup. I usually use the current date and / or time. For instance:

<link type="text/css" rel="stylesheet" href="site.css?120911" />

This forces the browser to download a new copy of the file when you need to update it, while maintaining consistent file names behind the scenes.

+5
source

, , .

: , - .


, , , , - URL.

, :

http://www.yoursite.com/my-file-123.css

, :

http://www.yoursite.com/my-file-124.css

URL- .


, ...

, ( , build- script, ), script.

+2

Source: https://habr.com/ru/post/1794788/


All Articles