Search code examples
javascriptjqueryjquery-uiautoloader

JavaScript Autoloader?


Is there a solution out there where I can have JavaScript/jQuery autoload dependent files when needed? For example, consider this scenario:

  1. I have an autoloader script listening for when a particular script needs to be loaded.
  2. A jQuery dialog() plugin is called.
  3. The autoloader is told to listen for when this plugin is called, and loads the jQuery UI.
  4. If more dialogs are called in the future, the required script will not be loaded.

Is this too much effort for simply trying to limit bandwidth? Should I just include all of the core files in one superpackage and be done with it?

Thank you for your time.


Solution

  • Yes you should inclde all of the scripts in one file. Or at least most of them groupped like this: jquery.js, global.js (that's where frequently - on more than one, two pages - used scripts should be) and page_specyfic.js. Imagine that a dialog() is called and the user has to wait for .js to download and plugins to initialise. Savings in bandwith (if any) wouldn't be worth harming the users expirience.