javascript - Google 托管库不必要地使用缓存断路器

标签 javascript jquery html ajax reload

我在仪表板上使用以下代码来不断刷新它而不会闪烁 How can I refresh a page with jQuery? :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
setTimeout(function() {
    $.ajax({
        url: "",
        context: document.body,
        success: function(s,x){
            $(this).html(s);
        }
    });
}, 4000);
</script>

但是,由于某些缓存破坏程序,这也会导致 javascript 每次重新加载。

enter image description here

Google 正在发送以下 header :

enter image description here

为了不让我自己和我的客户被 Google 屏蔽(那时不妨成为门诺派),有没有办法使用 Google CDN 而不引起这些额外的请求?

最佳答案

未经测试的警告:

$.ajax({
    url: "",
    dataType: "text", //dont parse the html you're going to do it manually
    success: function(html) {
        var $newDoc = $.parseHTML(html, document, false); //false to prevent scripts from being parsed.
        $('body').replaceWith(newDoc.find("body")); //only replace body
    }
});

更好的解决方案是模板化你的 body 。

关于javascript - Google 托管库不必要地使用缓存断路器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21761931/

相关文章:

html - 无法显示 Font Awesome 图像

javascript - 创建横幅,动态使用目录中的所有图像

javascript - 正确禁用提交按钮

javascript - 从 Chrome 扩展程序访问 Google Analytics window._gaq

javascript - 循环遍历 Javascript 数组的索引时重置变量

javascript - 如何避免在 anchor (<a></a>)标签点击时刷新页面?

jquery - 使用jquery从odata wcf服务获取json

javascript - 加载文件包含使用文档就绪功能不起作用

javascript - 如果在单击输入后按下按键

javascript - JQuery 值没有改变