PDA

View Full Version : Preventing the caching of CSS files


pardicity3
05-07-2003, 04:02 AM
I have searched far and wide for a solution to the problem of CSS files being cached. Granted, this is something that is probably good and that I should not be tampering with, but I frequently update my CSS files right now (as my site is still slightly under development) and I want the newest version to always be displayed. Unfortunatly this doesn't always happen because my browser likes to cache all the files.

I already prevent caching on my html files that change a lot by using php. This works great, but it's really not applicable to a CSS file.

I thought about using .htaccess but then I heard that mod_expires isn't usually turned on and thus most methods of preventing caching wouldn't work.

I know I myself can prevent my browser from caching, but that's not good enough. I want everyone to be viewing the latest stylesheet. Granted, once I get my stylesheets the way I want them I can let them be cached again, but for now I was wondering if there is anyway to prevent this?

oracleguy
05-07-2003, 05:52 AM
This is kinda an off the wall suggestion but what if you put a PHP inlcude in your header that points to some .inc file that has your style sheet in the in-line form? So when people see it, the styles are in the page themselves thus the code you already have to prevent the page from caching will prevent people from viewing the old stylesheet.

And when you are done tweaking it, you can just change the contents of your include to just be the html line that includes a stylesheet so it gets cached. Or take the PHP include out all together, whichever you feel like.

Does that make sense? I don't know if there is a better way but that's what I thought of first.

pardicity3
05-07-2003, 10:07 PM
Yeah, that makes perfect sense. At first I didn't really like your idea as I prefer external stylesheets, but, in a way, that is an external stylesheet. Also, the idea of getting rid of the .inc file once I have all my stylesheets the way I want them added to my support of your idea. It does seem like it may be the only viable solution. Thanks :thumbsup:

Richard
05-07-2003, 11:07 PM
Most ISPs have a port 80 proxy firewall which caches images, .htm files and css files anyway which is why even if you clear your own temporary files cache, it will still display the old css file unless you change the name of the file every time you update it.