避免 jQuery Mobile 使用 _=TIMESTAMP 查询字符串参数强制重新加载脚本/CSS

Jon*_*her 5 javascript jquery jquery-mobile

据我所知,如果你想将 JavaScript 或 CSS 文件与通过 ajax 自动加载的特定页面一起加载,那么你必须将 CSS/JavaScript 引用放入容器中<div data-role="page">

例子:

<div data-role="page" data-theme="e">
  <script type="text/javascript" src="/js/jquery/plugins/plugins.js"></script>
Run Code Online (Sandbox Code Playgroud)

一般来说,这工作得很好。然而,在这个过程中,脚本 url 被修改了:

/js/some_sepcial_script.js becomes e.g. js/some_sepcial_script.js?_=1299308309681
Run Code Online (Sandbox Code Playgroud)

1299308309681当前 Unix 时间戳在哪里,它会根据每个请求而更改,从而阻止缓存。我很确定这是预期的行为,但是如果您想让文件可缓存,有谁知道如何防止将时间戳附加到脚本/CSS url 中?

JRo*_*ero 3

你有没有尝试过:?

$.ajax ({
    // Disable caching of AJAX response */
    cache: false
});
Run Code Online (Sandbox Code Playgroud)

它应该全局更改 ajax 请求。我只是不确定外部脚本。

[编辑]

这是jquery mobile 1.0a3涉及的源代码:

var all = $("<div></div>");
                //workaround to allow scripts to execute when included in page divs
                all.get(0).innerHTML = html;
                to = all.find('[data-role="page"], [data-role="dialog"]').first();

                //rewrite src and href attrs to use a base url
                if( !$.support.dynamicBaseTag ){
                    var newPath = path.get( fileUrl );
                    to.find('[src],link[href]').each(function(){
                        var thisAttr = $(this).is('[href]') ? 'href' : 'src',
                            thisUrl = $(this).attr(thisAttr);

                        //if full path exists and is same, chop it - helps IE out
                        thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );

                        if( !/^(\w+:|#|\/)/.test(thisUrl) ){
                            $(this).attr(thisAttr, newPath + thisUrl);
                        }
                    });
                }
Run Code Online (Sandbox Code Playgroud)

那里没有添加缓存阻止参数。

[编辑2]

我知道这超出了解决问题的方法,但您是否尝试过动态加载 js,如下所述: http: //www.javascriptkit.com/javatutors/loadjavascriptcss.shtml

(我知道这可以通过 jQuery 完成,但出于测试目的,我试图避免使用 jQuery)