Thursday, September 26, 2013

LazyJS, loading javascript asynchronously with execution order

By reading book High Performance JavaScript I discovered very useful library LazyLoad created by Ryan Grove of Yahoo! Search. LazyLoad is capable of asynchronously loading javascript and css files and executing them in correct order. In development of our projects we require only loading JavaScript files asynchronously and that's why we created modified version called LazyJS which is significantly smaller (1232 Bytes minified js and 2331 Bytes minified js with copyright notice) and require less memory allocation. When inlined into page and gzipped with other content its almost unnoticeable.
LazyJS minified code on GitHub

Example of use:
LazyJS.js(["/s/jquery-2.0.3.min.js","/s/jquery.Jcrop.min.js","/s/js.js"], null);


UPDATE:
Recently I discovered another option which is described in following blog post
Loading your javascript files asynchronously with script inspired by google analytics. It is worth to give it a try.

No comments: