Ok, this is starting to annoy and Google has yet to provide any clear answers.

I'm dynamically creating CSS based on users choice of theme colours. Easy enough, done with PHP but the code is irrelevant here, the problem being that IE is caching the old CSS and upon loading a theme it's not producing the new CSS without an F5 refresh. Firefox, Chrome and Safari all produce the desired effect.

I'm sure it's something simple I'm overlooking but for the sake of my sanity please clue me in.

Cheers,

Dalefish

Recommended Answers

All 7 Replies

Simple solution, especially if you're using PHP would be to add a timestamp to the end of the filename. E.g.

stylesheet.css?t=1234567890

This will result in the stylesheet link being different everytime, hence the browser cannot cache the file :)

Hope this helps.

R.

alternatively, you could just trigger a refresh

Sillyboy, tried a refresh, and using a third page with a redirect before posting neither worked, but thanks for the answer.

Robothy, simple yet effective, thanks.

This is a setting in the browser, not your code. Each user has to turn off the caching of pages and/or enable checking for changed files.

MidiMagic, The solution of generating a random URL extension, either time-stamp or otherwise, as suggested by robothy, has worked for me.

url now reads: style_user.css?t=0.84755300 1234945905
file remains: style_user.css

The timestamp is generated with PHP and inserted as a variable (for anybody else needing a similar solution).

I suppose the best solution would be to use the timestamp for when the file was last modified. Then caching can take place if the file is the same. If the file has been modified, obviously you need to override the caching.

MidiMagic, if it is a browser setting which cannot be overridden from the server side, surely that would mean websites could never be updated by their developers?

R

MidiMagic, if it is a browser setting which cannot be overridden from the server side, surely that would mean websites could never be updated by their developers?

No, just that the user needs to hit the refresh button to update the cache.

This is usually set to minimize download traffic on dial-up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.