避免 jQuery Mobile 使用 _=TIMESTAMP 查询字符串参数强制重新加载脚本/CSS
据我所知,如果您想将 JavaScript 或 CSS 文件与通过 ajax 自动加载的特定页面一起加载,那么您必须将 CSS/JavaScript 引用放在
示例:
<div data-role="page" data-theme="e">
<script type="text/javascript" src="/js/jquery/plugins/plugins.js"></script>
一般来说,这工作得很好。然而,在此过程中,脚本 URL 被修改:
/js/some_sepcial_script.js becomes e.g. js/some_sepcial_script.js?_=1299308309681
其中 1299308309681
是当前的 Unix 时间戳,它会根据每个请求而更改,从而阻止缓存。我很确定这是预期的行为,但是如果您想让文件可缓存,有谁知道如何防止将时间戳附加到脚本/CSS url 中?
As far as I know, if you want to load JavaScript or CSS files together with a specific page that is automatically loaded via ajax then you have to put the CSS/JavaScript references within the <div data-role="page">
container.
Example:
<div data-role="page" data-theme="e">
<script type="text/javascript" src="/js/jquery/plugins/plugins.js"></script>
In general, this works fine. However, somewhere along the way, the script url gets modified:
/js/some_sepcial_script.js becomes e.g. js/some_sepcial_script.js?_=1299308309681
Where 1299308309681
is the current Unix timestamp which changes on every request and thus prevents caching. I am pretty sure that this is intended behaviour but does anyone know how you can prevent the timestamp from being appended to the script/CSS urls if you want to make the file cacheable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你尝试过吗:?
它应该全局更改 ajax 请求。我只是不确定外部脚本。
[编辑]
这是 jquery mobile 1.0a3 涉及的源代码:
那里没有添加缓存阻止参数。
[编辑2]
我知道这超出了解决问题的方法,但是您是否尝试过动态加载js,如下所述: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
(我知道它可以通过 jQuery 完成,但出于测试目的,我试图避免使用 jQuery)
Have you tried:?
It should globally change ajax requests. I'm just not sure about external scripts.
[EDIT]
This is the source code involved for jquery mobile 1.0a3:
Nothing on there adds a cache preventing param.
[EDIT 2]
I know this goes beyond troubleshooting to a work around but have you tried dynamically loading the js like explained here: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
(I know it can be done through jQuery but for testing purposes I'm trying to avoid jQuery)
如果我包含 jQuery 1.4.3 而不是 1.5,一切都会正常工作。这对我来说是一个足够的解决方案。再次感谢您的支持。
if I include jQuery 1.4.3 instead of 1.5 everything works fine. That's a sufficient solution for me. Thanks again for your support.
尝试跑步:
它会改变这种行为吗?
Try running:
Does it change this behavior?