Using JavaScript, how can I prefetch another web page on my site?
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开发者_如何学Python 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?
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.
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.
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. :-(
精彩评论