Is it possible to preload an HTML page before displaying it?

HyderA picture HyderA · Aug 18, 2009 · Viewed 14k times · Source

I'm not referring to preloading images, I want to preload an HTML page using JQuery.

Answer

Rob Fuller picture Rob Fuller · Aug 18, 2009

Ajax the content in then use as you wish:

var myPrefetchedPage;
$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    myPrefetchedPage = html;
  }
})

myPrefetchedPage is now the full content - which can be injected into the current page (completely replacing the page if required.

If you are just trying to leverage caching as much as possible a hidden iFrame may work better. You can then use jQuery to cycle the iframe src to fetch multiple pages.