gpt4 book ai didi

jquery - Struts 2 jQuery 插件项目中的 js 文件中将添加 "_=13 digits"

转载 作者:行者123 更新时间:2023-12-01 04:08:30 24 4
gpt4 key购买 nike

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

<script type="text/javascript"
src="js/sample.js"></script>

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

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函数,它会用下划线加数字来调用

最佳答案

Struts2 jQuery 插件使用 jQuery,此功能与不在 jQuery 中缓存页面有关。该插件可配置为通过 head 的属性 ajaxcache 更改此功能。标签。来自文档

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>

关于jquery - Struts 2 jQuery 插件项目中的 js 文件中将添加 "_=13 digits",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24122285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com