views:

31

answers:

1

hi,

is there a good jquery plugin for lazy loading css+js which also supports callback-when-loaded? i'd like to pass eg. an array of .js and .css files and have a global callback for when anything finished loading. any ideas?

thx

+1  A: 

You might want to try LabJS. Here's an example from their documentation:

<script>
   $LAB
   .script("framework.js").wait()
   .script("plugin.framework.js")
   .script("myplugin.framework.js")
   .wait(function(){
      myplugin.init();
      framework.init();
      framework.doSomething();
   });
</script>

Note that <script> is for HTML5 pages; use <script type="text/javascript"> for older pages.

You can pass your own callbacks to wait anywhere in the chain, but depending on your situation, you may need to dynamically convert your array of filenames into a chain of script calls.

Ron DeVera