如何强制缓存的css文件重新加载在JSP(即不是PHP)? [英] How can I force a cached css file to be reloaded on a JSP (i.e. not PHP)?

查看:169
本文介绍了如何强制缓存的css文件重新加载在JSP(即不是PHP)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改一个css文件,这将对我的网站进行大幅更改。有没有办法强制客户端重新加载css,以便他们拿起新的更改。不幸的是,要求数千人CTRL + F5或清除缓存不是一个选项。我在几个博客上阅读了关于在css文件名作为参数添加当前日期的博客。

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.

推荐答案

唯一的查询字符串参数到css文件的末尾url

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:

要从web.xml文件加载它,请使用以下命令:

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")%>" />

这在web.xml中

<context-param>
   <param-name>cssBuildNumber</param-name>
   <param-value>123</param-value>
</context-param>

这篇关于如何强制缓存的css文件重新加载在JSP(即不是PHP)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆