Delay Loading The Print Stylesheet

Posted by Duncan McDougall on July 20, 2010

Browsers can only download a limited number of files at a time from the same host when loading a web page. This is as low as 2 files on IE 6 & 7. To allow the page to appear faster a best practise is to prioritise important files like the main css, template images and the main content. Since the print stylesheet is rarely used, especially not within the first few seconds of page load I recommend loading this file last.

This isn’t as simple as referencing the file at the end of your HTML since in some browsers the page is not rendered until all css is loaded. A JavaScript solution is required. Add the following JS to load on document load.

I’ve avoided using jQuery’s appendTo as during my testing IE7 didn’t like it. Barebones JavaScript will do. Now for the no JavaScript use the noscript tag in the head to load the print stylesheet in the normal position.

The savings won’t be huge but every little helps so why not.

See also: Delay loading your print css - Stoyan Stefanov

Update: Deferred downloading of print stylesheets is coming to a future release of WebKit.



comments powered by Disqus