tags:

views:

1281

answers:

6

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

+1  A: 

Why yes it is! You could do something like having an iframe for your content, fetching the content separately, and then filling the frame.

Justin
+4  A: 

You could put everything in a div that is not visible, and once the document is ready, make the div visible - although this really isn't "pre-loading" - it is just not displaying anything until everything is loaded.

BrianH
A: 

Set a class on the body to hide it, then remove it using Javascript at the onload event.

(But why you would want to do this is another question.)

edeverett
+2  A: 

Is this link any help to you? http://www.innovatingtomorrow.net/2008/04/30/preloading-content-jquery

Aaron
+2  A: 

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.

Rob Fuller
Thanks! That I guess is what I needed, I'd only need to cache the js associated with the page, not the html page itself.
gAMBOOKa
A: 

Yes, you can load the page via jQuery.get and then do what you want to with it (in string form) before displaying it. If you insert it into a hidden container, you can manipulate it with the DOM first.

T.J. Crowder