Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force a cached css file to be reloaded on a JSP (i.e. not PHP)?

I am altering a css file which will make drastic changes to my site. Is there a way to force the clients to reload the css so that they pick up the new changes. Unfortunately asking thousands of people to CTRL + F5 or clear their cache isn't an option. I read on a couple of blogs about appending todays date on the css filename as a parameter would work.

like image 855
edwardmlyte Avatar asked Jun 01 '26 22:06

edwardmlyte


1 Answers

You can add a unique query string parameter on to the end of the css file url

<link rel="stylesheet" type="text/css" href="/my/css/file.css?123" />

Just increment the number each time you make an update.

EDIT:

To load it from the web.xml file use the following:

<link rel="stylesheet" type="text/css" href="/my/css/file.css?<%=application.getInitParamer("cssBuildNumber")%>" />

and this in web.xml

<context-param>
   <param-name>cssBuildNumber</param-name>
   <param-value>123</param-value>
</context-param>
like image 127
3urdoch Avatar answered Jun 03 '26 11:06

3urdoch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!