在Struts 2 jQuery插件项目中,考虑一个简单的JSP页面,其中包含一个JS文件。
<script type="text/javascript"
src="js/sample.js"></script>当您查看实际请求的URL (例如使用Firefox firebug)时,您会发现URL末尾添加了13位数的a下划线:
localhost:8080/js/sample.js?_=1402322518885当您刷新页面时,它将如下所示
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函数,它将被用下划线加号调用。
发布于 2014-06-09 17:00:05
Struts2 jQuery插件使用jQuery,这个特性与在jQuery中不缓存页面有关。插件是可配置的,可以通过属性ajaxcache更改head标记的这个特性。从医生那里
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中使用下面的代码将更改,而不是缓存默认值
<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>https://stackoverflow.com/questions/24122285
复制相似问题