CSS caching and changes

admin

Administrator
Staff member
I have an application consisting of JSPs, all use the same CSS file. The CSS is being cached on browsers, which is normally OK. Except if I ever need to change the CSS, then my changes won't be loaded by the browsers because the old version still loads from the cache.

What I ideally want to do is have our homepage get the CSS file from the server not from the cache, so the latest version will always be put in the cache when they logon (the logon page is the homepage.) Since users only logon once, it seems ideal to get the latest CSS file only once also.

Any ideas on how to code a JSP file so that the CSS file will always be loaded from the server and not the cache?I think all you can really do is tell the users to set their browsers up to check every time then make sure the css file has the right time stamp according to the server. I don't believe there is anything you can do from the JSP standpoint to do that. Maybe making sure the index page is always expired would help indirectly.You could also place a note at the top of the screen telling readers to hit Ctrl + F5 (Apple + F5) to reload the page (and fetch the new style sheet). Also, if the CSS is going to change every time, why keep it in a separate file?

What you could do is keep the CSS rules that don't change in an external CSS file, then add some CSS rules inside the <style> tags.

<style type="text/css" media="screen">
<!--
@import "global.css"; /* Styles that don't change */

/* Insert styles that do change. */
-->
</style>I believe you can add the functuality to your META tags. It supports no-cache.

I am at work so I don't have an example to show. I will see about getting one this weekend for you if you need it.
 
Back
Top