1

I have a static HTML page for which I have set a cache-control max-age of 6 months, and it calls a style_v1.css file with a max-age of a year. What happens when I update the HTML file to call my redesigned style_v2.css?

I realise that users who have both files cached will see the old version, and users who have the CSS cached but not the HTML will download style_v2.css and everything will be fine. But is there a chance that the CSS file falls out of a user's cache, but the HTML file doesn't? In which case, what happens when the HTML page looks for style_v1.css and it isn't there anymore? Is the only solution to keep all previous versions of the CSS file on the server?

1

Don't overthink people's caches too much.

Your web server is the authority on what's up-to-date, just make sure that the css files referenced by your current html file are there and you'll be good to go.

If you no longer reference style_v1.css from any of your pages, then it is safe to delete it.

1

The situation you describe is very unlikely. Most browsers don't cache files for more than a few days before the space in cache is reclaimed. Browsers usually push items out of cache based on how recently they were used. Since the files are used together they will probably get pushed out of cache at the same time.

If you are worried about it, you can redirect your old CSS file to the new one. The old page may not look perfect with the new CSS, but it would be better than the user getting no styling.

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.