Question

Is there any way to determine or force a CSS file to be re-cached if the user is operating off an old file?

Was it helpful?

Solution

The single surest way to ensure that everyone reloads your new file is to change its URL. A reasonable way to do this without actually renaming it is to tack on a random string:

<link rel='stylesheet' href='/mystyles.css?random=87365835'>

That's using a sledgehammer to crack a nut, and bypassing all the HTTP mechanisms that exist to do this, but it will absolutely work everywhere, whereas the other techniques all have caveats.

Edit: @jitter: You don't have to change the URL automatically for every request - you could base it on the timestamp of the CSS file, or even just change it by hand when you want to ensure that the CSS gets reloaded.

OTHER TIPS

You can try editing the server etags: http://developer.yahoo.com/performance/rules.html#etags

But the preferred method is probably to rename your CSS file, such as with the date or the build number, so that users will always have the latest.

Check this solution instead of using xx.css?rand=213213213

What is an elegant way to force browsers to reload cached CSS/JS files?

Or google for "auto versioning" plus adding javascript or css. Or "automatic asset versioning"

It uses an automatic approach which changes the path of the URL part no by appending get variables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top