Search code examples
jquerypreload

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


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


Solution

  • 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.