6

Does anyone knows ajax script loader that allows lazy loading of js and css files and also consist of dependency list that can be defined in external script?

Naor
  • 22,523
  • 46
  • 144
  • 260
  • What do you mean with "lazy loading of js ?" ? – genesis Jun 05 '11 at 11:15
  • @genesis: I'm guessing he means only to load a JS file if it's required, for example a set of thumbnails may be loaded and then require "fancybox" support, then the relevant JS/CSS/images can be loaded as required. – Marcel Jun 05 '11 at 11:22
  • aha. Su just add it into  in ajax loaded page. or not? – genesis Jun 05 '11 at 11:23
  • @genesis: Marcel explanation is exactly what I ment. I can't just add it to the – Naor Jun 05 '11 at 11:43

4 Answers4

4

Why not use http://unwrongest.com/projects/lazy/ ?

Daniel Ruf
  • 7,359
  • 11
  • 61
  • 112
1

In my various projects I use LABjs. Easy and flexible :)

sitifensys
  • 1,994
  • 15
  • 28
1

If you need a smart why to load or skip resources, see http://yepnopejs.com/ :

yepnope is an asynchronous conditional resource loader that's super-fast, and allows you to load only the scripts that your users need.

Modrnizr is a good example of yepnoejs usage.

Udi
  • 27,155
  • 8
  • 91
  • 123
  • Can I define dependencies list in yepnoejs? – Naor Jun 05 '11 at 11:56
  • @Naor: I do not see any smart built in dependency features in yepnopejs. However: 1: `On top of all that, inside of your array, each item can be a test object, another array, or a string literal...`, so you can create a master object with your requirements. 2. You can use the callbacks and the complete event, look for `What happens if I use yepnope inside of a yepnope callback?`. 3: You can probably further load stuff from within loaded scripts, although this is not optimal in many ways. – Udi Jun 05 '11 at 12:44
1

Just include

<script src="your_lazy.js"></script>

in script (html) which is loaded with your ajax-called page

genesis
  • 49,367
  • 20
  • 94
  • 122