example: document.write withOUT ControlJS
This page contains a script that uses document.write to output a blue rectangular DIV.
This script is configured to take 2 seconds to download and 2 seconds to execute.
The time at which the document.write takes place is shown, as well as the page load time.
There's also an image at the bottom of the page that takes 2 seconds to download.
This page does uses ControlJS.
This has several benefits:
- The script is loaded asynchronously so the entire page renders immediately.
- The async script load also benefits IE because it allows the script and image to download in parallel cutting 2 seconds off the page load time.
- Another 2 seconds is shaved off the page load time because the script is executed after the page is loaded.
- Even though the script is executed after the document is loaded, the document.write still works. (If you look at the blue rectangle in a DOM viewer like Firebug you'll see it's wrapped in a SPAN that was inserted by ControlJS.)
See ControlJS part 3: overriding document.write for more information.