最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin7浏览0评论

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.

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.

Share Improve this question asked Apr 13, 2011 at 10:19 edwardmlyteedwardmlyte 16.6k23 gold badges61 silver badges83 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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>
发布评论

评论列表(0)

  1. 暂无评论