Preloading the second page while viewing the current page

Say my site has 5 pages of content. Is it possible to preload the following two pages while the visitor views the first page. Therefore, when they click on the link to the second or third page, it appears immediately.

+3
source share
1 answer

Of course, you may have some invisible containers:

HTML

<div id="page">
  <a href="page2.html" id="page2-link">Go second page</a>
</div>
<div id="page2">
</div>

CSS

#page2 { display:none }

Javascript

Then, when in javascript, preload the second page after loading it and put it in the invisble container:

$().ready(function(){
  $('#page2').load('page2.html #page');
});

And when the link is clicked, just show the hidden container with the selected page and delete another, or just hide so as not to load again when the user wants to return or something like that.

$().ready(function(){
  $('#page2-link').on('click',function(){
       $('#page').html( $('#page').html() ); //this will replace html content
  });
});
+2

All Articles