Tuesday, September 16, 2008

A Technique for Lazy Script Loading

Bob Matsuoka has written a guest article on the topic of lazy script loading. Thanks so much Bob!

A recent article "Lazily load functionality via Unobtrusive Scripts" discussed how to lazily load Javascript script files by appending script elements to the HEAD tag.

While this works as expected, I've found that for best results, you should also consider tracking which scripts have been loaded in order to prevent re-loading an already loaded script, and more importantly supporting callbacks so that you can guarantee loading of scripts prior to calling functions that depend on that code.

LazyLoader.load('js/myscript1.js');

http://ajaxian.com/archives/a-technique-for-lazy-script-loading

MSN is now implementing a technique for loading JavaScript in a way that doesn’t stall the rendering of the document. They use Dynodes, a technique I also recommend for loading functionality on demand so it only consumes bandwidth when it is needed.

http://www.artzstudio.com/2008/07/beating-blocking-javascript-asynchronous-js/
http://www.yuiblog.com/blog/2008/07/22/non-blocking-scripts/
http://www.jspatterns.com/javascript-includes-and-domcontentloaded-event/

No comments: