Question

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.

enter image description here

Google is sending with the following headers:

enter image description here

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top