0

I'm trying to employ caching to speed up the response time of a website. Most of the documentation I have read suggests setting expiration to +1 month from time of access as follows:

ExpiresActive On
ExpiresByType text/css "access plus 1 month"

I'm concerned that if I update a css file that the client will not get the updated file.

Is it possible to ensure the client downloads a new version of a file if it is modified?

Any help much appreicated

1

Your concern is correct - clients whose browsers have retrieved the file will typically not receive the updated version until 1 month after they accessed it unless they happen to have cleared their browser cache or they do a reload on the page.

One way around this is when you update the CSS file, change the HTML that references it to have ?v=2 or ?v=3 etc. at the end of the link tag's href attribute (i.e. after the .css). Browsers view that as a unique URL and will thus download the new copy, yet it will point to the same physical .css file on your server.

<link rel="stylesheet" type="text/css" href="/styles.css" />

becomes

<link rel="stylesheet" type="text/css" href="/styles.css?v=2" />
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.