首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"_=13数字“将添加到Struts 2 jQuery插件项目中的js文件中。

问"_=13数字“将添加到Struts 2 jQuery插件项目中的js文件中。
EN

Stack Overflow用户
提问于 2014-06-09 14:20:56
回答 1查看 160关注 0票数 2

在Struts 2 jQuery插件项目中,考虑一个简单的JSP页面,其中包含一个JS文件。

代码语言:javascript
复制
<script type="text/javascript"
    src="js/sample.js"></script>

当您查看实际请求的URL (例如使用Firefox firebug)时,您会发现URL末尾添加了13位数的a下划线:

代码语言:javascript
复制
localhost:8080/js/sample.js?_=1402322518885

当您刷新页面时,它将如下所示

代码语言:javascript
复制
localhost:8080/js/sample.js?_=1402322518886
localhost:8080/js/sample.js?_=1402322518887
localhost:8080/js/sample.js?_=1402322518888

您可以通过访问http://struts.jgeppert.com/struts2-jquery-showcase/index.action来看到这一点。打开firebug网络控件,然后转到widgets/spinner菜单,您可以看到globalize.js将被称为类似于globalize.js?_=1402323154341的东西。

这样可以防止在客户端上缓存JS。你知道这是什么吗?我们怎样才能阻止它?!我发现这并不适用于所有的JS文件,只要我发现如果Ajax加载的内容中包含一个JS函数,它将被用下划线加号调用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-09 17:00:05

Struts2 jQuery插件使用jQuery,这个特性与在jQuery中不缓存页面有关。插件是可配置的,可以通过属性ajaxcache更改head标记的这个特性。从医生那里

代码语言:javascript
复制
Name        ajaxcache       
Required    false       
Default     false       
Evaluated   false       
Type        Boolean     
Description If set to false it will force the pages that you request to not be 
            cached by the browser. 

在index.jsp中使用下面的代码将更改,而不是缓存默认值

代码语言:javascript
复制
<s:if test="%{theme == 'showcase' || theme == null}">
    <sj:head debug="true" compressed="true" jquerytheme="showcase" customBasepath="themes" loadFromGoogle="%{google}" ajaxhistory="%{ajaxhistory}" defaultIndicator="myDefaultIndicator" defaultLoadingText="Please wait ..." ajaxcache="true"/>
</s:if>
<s:else>
    <sj:head debug="true" compressed="true" jquerytheme="%{theme}" loadFromGoogle="%{google}" ajaxhistory="%{ajaxhistory}" defaultIndicator="myDefaultIndicator" defaultLoadingText="Please wait ..." ajaxcache="true"/>
</s:else>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24122285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档