【问题标题】:Jquery disable cache buster for external scripts downloaded after calling the jquery load function调用jquery加载函数后下载的外部脚本的jquery禁用缓存破坏器
【发布时间】:2015-08-15 14:44:11
【问题描述】:

当通过$.load加载html内容时,当html内容包含<script>标签引用javascript文件时,链接的Javascript文件会附加一个cache busting参数,防止文件被浏览器缓存。

因此,它不是请求<script src="/js/foo.js"> 之类的东西,而是请求<script src="/js/foo.js?_=123123">,导致每次都加载脚本。

有没有办法禁用这种行为?

【问题讨论】:

    标签: javascript jquery html caching


    【解决方案1】:

    你可以尝试强制缓存

    $.ajax({
        url: "/yourpage",
        cache: true,
        dataType: "html",
        success: function(data) {
            $("#content").html(data);
        }
    });
    

    .

    $.ajaxSetup({
    cache: true // Enable cache as jQuery won't let the script be cached by default
    });
    

    【讨论】:

    • ajaxSetup 是全局的,所以我不想使用它。不过,我可能会尝试您的第一个建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    相关资源
    最近更新 更多