Preloading subsequent HTML pages

Discussion in 'Javascript' started by Charles, Jan 27, 2008.

  1. Charles

    Charles Guest

    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,
     
    Charles, Jan 27, 2008
    #1
    1. Advertising

  2. Charles wrote:
    > How would you preload subsequent [HTML documents]?


    With prefetching, which does not require scripting.


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Jan 27, 2008
    #2
    1. Advertising

  3. Charles

    Charles Guest

    On Jan 27, 7:12 am, Thomas 'PointedEars' Lahn <>
    wrote:
    > With prefetching, which does not require scripting.


    Thanks. Yeah, the only problem is that basically only Mozilla browsers
    support it: http://en.wikipedia.org/wiki/Link_prefetching

    Any other suggestion in the meantime? I was thinking about using an
    Ajax function after loading the initial page and using the GET method
    to push subsequest pages. Would this work?
    Thanks.
     
    Charles, Jan 27, 2008
    #3
  4. Charles

    Charles Guest

    On Jan 27, 11:33 am, Charles <> wrote:
    > > With prefetching, which does not require scripting.


    I tried it in Firefox, but it didn't keep the page in cache. I tried
    the Ajax way and it works in FF and IE, but not in Opera:
    http://jsite.dreamhosters.com/preload/

    I'm gonna get in touch with the Opera team to find out why.
     
    Charles, Jan 27, 2008
    #4
  5. Charles

    Charles Guest

    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.
     
    Charles, Jan 27, 2008
    #5
  6. Charles

    Charles Guest

    Oh, actually I swapped the two URLs.
     
    Charles, Jan 27, 2008
    #6
  7. Charles wrote:
    > 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
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Jan 27, 2008
    #7
  8. Charles

    Charles Guest

    On Jan 27, 8:37 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > Please search the newsgroup for suggestions on how to perform several
    > asynchronous XHRs.


    I think you'll be happy to see what I've come up with. I'm now able to
    prefetch pages using Javascript in asynchronous mode. Please have a
    look: http://preload-pages-with-javascript.dreamhosters.com/
    Cheers.
     
    Charles, Feb 3, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Breakspear
    Replies:
    0
    Views:
    463
    Ryan Breakspear
    Nov 18, 2003
  2. Guadala Harry
    Replies:
    4
    Views:
    809
    Teemu Keiski
    Sep 11, 2004
  3. =?Utf-8?B?aGRldg==?=
    Replies:
    0
    Views:
    306
    =?Utf-8?B?aGRldg==?=
    Oct 8, 2004
  4. bb
    Replies:
    0
    Views:
    590
  5. Sam S.
    Replies:
    2
    Views:
    202
    Tad McClellan
    Feb 9, 2005
Loading...

Share This Page