Google Hosted Libraries is unnecessarily using cache breakers

风流意气都作罢 提交于 2019-12-19 10:10:27

问题


I am using the following code on our dashboard to refresh it constantly without flicker 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>

However, this is causing the javascript to reload each time too due to some cache breakers.

Google is sending with the following headers:

In the interest of not getting myself and my clients blocked from Google (might as well become a Mennonite at that point) is there a way use Google CDN without causing these extra requests?


回答1:


Warning untested:

$.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
    }
});

A better solution would be to template your body.



来源:https://stackoverflow.com/questions/21761931/google-hosted-libraries-is-unnecessarily-using-cache-breakers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!