2

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?

5
  • Not sure how the empty url works... Have you tried setting cache:true on the ajax options? Commented Feb 13, 2014 at 18:01
  • No dice with: $.ajax({ url: "", cache: true, context: document.body, success: function(s,x){ $(this).html(s); } }); Commented Feb 13, 2014 at 18:02
  • Hmm.. Figured that would be too easy ;-) Commented Feb 13, 2014 at 18:02
  • 1
    Since you've already loaded jQuery (and all other scripts that you need) instead of refreshing all of body (where the script tags are) refresh a container that doesn't have the script tags in it. Commented Feb 13, 2014 at 18:04
  • There's also an interesting question to be asked about why google does this 'unnecessary' cache breaking. I suspect that the whole reason for google for hosting these libraries is so that they can track the users of the pages that use the libraries. Hence they don't want those tracking hits reduced by caching. Commented Aug 19, 2014 at 16:46

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.