FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Force reload CSS

 


kv
I have a css file which is quite big. I don't want users to download it every time they visit the site. It will be cached in the browser. Occasionally, though, I will change the css to change the look and feel of the site. Most of the times, new css won't be downloaded and browser still uses the cached version. Is there a way to force browsers to use new css when a new version is available? It should use cached version if css has not changed. I want to do it from server side. I don't want to ask users to change any settings.
Stubru Freak
Simple solution: change the filename of the css to include the date. For example: style20060508.css
If you change that filename in html whenever there's an update (which can be done automatically with php by just changing one variable), the browser will assume it's a different file (which it is!) and it will redownload.
If you really want to keep the filename style.css you could even include the following mod_rewrite code in your .htaccess:

Code:
RewriteRule ^style[0-9]{8}.css$ style.css


This will rewrite all urls like style20060508.css to your file style.css. So while the browser thinks it is downloading a different file it is actually downloading the updated old file.
Donutey
stubru the added disclaimer thing at the bottom of your sig awesome lol...
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.