Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

preload

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

like image 633
HyderA Avatar asked Aug 18 '09 16:08

HyderA


People also ask

How do you preload a page in HTML?

In the header you have to add <link rel="preconnect" href="https://example.com/"> Prefetch downloads the resource and stores it in the browser cache to use it later. You can do <link rel="prefetch" href="imgs/image.

How do I add preload to my website?

In Google Chrome right click anywhere on the page and click on inspect element, this will bring up the developer tools. Right click on the body element and add a new attribute class="loaded" . Hit enter and you'll see our preloader screen disappear.

What does it mean to preload web pages?

Chrome helps you open webpages faster by predicting where you might go next on the page. The browser preloads the page's data in the background, so the page can open immediately if you tap its link.

What is link preload in HTML?

The preload value of the <link> element's rel attribute lets you declare fetch requests in the HTML's <head> , specifying resources that your page will need very soon, which you want to start loading early in the page lifecycle, before browsers' main rendering machinery kicks in.


3 Answers

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.

like image 176
Rob Fuller Avatar answered Oct 01 '22 22:10

Rob Fuller


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.

like image 45
BrianH Avatar answered Sep 29 '22 22:09

BrianH


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

like image 20
Justin Avatar answered Sep 29 '22 22:09

Justin