您的位置:首页 > Web前端 > CSS

JSP中,防止 css js img 等文件的缓存的方法

2016-01-14 14:18 549 查看
被这个问题困扰过很多回,上网也查过很多方法,基本上就是在 <head> 标签中添加如下元素:

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

 

可是,照做了也没用。无意中想到,能不能在css之类的文件后面加上一个随机数或者当前时间什么的呢?试了一下,还真行:

<link rel="stylesheet" href="<%=request.getContextPath()%>/css/endparameter.css?<%= System.currentTimeMillis()%>" />

 

但如果像下面这么写就是不行的, 因为script标签不能被嵌入到 link 中使用吧:

<link rel="stylesheet" href="<%=request.getContextPath()%>/css/endparameter.css?"+ <script type="text/javascript">Math.random()</script> />

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: