Preloading subsequent HTML pages

C

Charles

Hello,

I have a common company web site with the home page, products,
services, about us and contact pages. I'd like to preload the 4 other
pages in the background when I access a page to make the site faster.
I already preload images properly. I thought about using a 1x1px
iframe but it's not very nice. So I tried considering .html pages as
if they were image files and I tried this code:

var preload=new Image();
preload.src="products.html";

But this code doesn't preload the products.html page. It seems the
Image() object only handles images, as the name implies, eh eh...
How would you preload subsequent pages?
Thanks,
 
C

Charles

I tried both synchronous and asynchronous modes. Here are my findings:

1. In synchronous mode, I'm able to prefetch subsequent pages but the
browser freezes for a few seconds, it's not an ideal situation. It
happens with all browsers I've tested. Here's an example that
prefetches pages in synchronous mode: http://jsite.dreamhosters.com/preload/pages_asynchronous.html
and here's the line that I use: xmlHttp.open("GET",pages,true);

2. In asynchronous mode, I'm unable to fetch pages, it seems the loop
is executed right away without fetching anything. I don't understand
very well what happens behind the scene. But at least the browser
doesn't freeze! Here's an example that uses asynchronous mode:
http://jsite.dreamhosters.com/preload/pages_synchronous.html and that
doesn't work. Here's the line that I use:
xmlHttp.open("GET",pages,false);

What do you think I can do to prefetch pages in asynchronous mode?
Thanks.
 
T

Thomas 'PointedEars' Lahn

Charles said:
Here's an example that prefetches pages in [a]synchronous mode:
http://jsite.dreamhosters.com/preload/pages_asynchronous.html
[...] and that doesn't work.
http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork

Here's the line that I use:
xmlHttp.open("GET",pages,false);

What do you think I can do to prefetch pages in asynchronous mode?


First, remove the window.alert() call which suspends execution until the
alert window is closed; modify the document tree instead.

Second, you have a misconception about when the event listener is called:
its *definition* (here: assignment of the FunctionExpression) has to come
after you call XHR::eek:pen() but *before* you call XHR::send(), and it is
automatically called on event by the implementation later.

Third, you are reusing the same object to open a new connection before the
first one is closed. Therefore, I get

| uncaught exception: [Exception... "Component returned failure code:
| 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult:
| "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame ::
| javascript: eval(__firebugTemp__); :: anonymous :: line 1" data: no]
|
| Line 0

in Firebug.

Please search the newsgroup for suggestions on how to perform several
asynchronous XHRs.

You don't need to try "Msxml2.XMLHTTP" here, because "Microsoft.XMLHTTP"
selects MSXML 3.0 or earlier which suffices for your purpose.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top