views:

288

answers:

3

I have Large.html, which is a web page that has a lot of images and javascript on it which takes a long time to load.

From other pages (a.html, b.html) how can I use JavaScript to prefetch Large.html (and all of the elements on the page) so that I can get the page cached in the users browser to help speed up page loading.

Would I need to use a hidden IFRAME?

+1  A: 

You could just load the body of the page, put it into the innerHTML of a div that has 'display: none', and wait for a bit, then make the current div have a display of none and the div with the new page becomes visible.

It may still need to go out and actually download the images, but it should basically be preloaded.

James Black
You mind writing the code for this. Sounds awesome.
mp_
@mp_ - I tend not to enjoy writing code, as you won't learn from that, but I can give advice. For example, if you use jQuery, then it will take care of the ajax call you need to make. You then need some cgi application (REST service) to connect to, and in your ajax call you will return the body that is needed. jQuery will make your life easier for doing this.
James Black
A: 

yes, i would use a Hidden Iframe. That will, in general, take care of exercising scripts that might run and load in additional assets on that slow-to-load page.

Scott Evernden
How do I load the large.html IFRAME on a.html __after__ a.html fully loads. I'd hate for a.html to load slowly because it's blocking downloading large.html before a.html finishes rendering
mp_
A: 

If you do this, be sure to do it after the load of the a.html page so that you are not stopping the user interacting on this page.

I say if, because you often don't know for sure that the user will load the Large.html page.

Other than that if the large parts of the other page are mostly images, I would load them, and not the entire page (html, css, js, & images) in an iframe.

I've seen too many sites that try to load the entire content (hidden) in an iframe... and in the process make the current page unusable. :-(

scunliffe
How do I load a hidden IFRAME _after_ a.html loads?
mp_