HyderA
HyderA

Reputation: 21371

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.

Upvotes: 8

Views: 14730

Answers (6)

AadityaTaparia
AadityaTaparia

Reputation: 31

You can use: The browser will download assets for and render an entire page in the background. When user click that "yourpage" link, the page will display almost instantly.

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1074178

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.

Upvotes: 0

Rob Fuller
Rob Fuller

Reputation: 514

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.

Upvotes: 9

edeverett
edeverett

Reputation: 8218

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

Upvotes: 0

BrianH
BrianH

Reputation: 8241

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.

Upvotes: 4

Justin
Justin

Reputation: 9791

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

Upvotes: 2

Related Questions