ajax, JavaScript, jquery

An asynchronous JavaScript loader and dependency manager

reference :


Sometimes it makes sense to dynamically load JavaScript library code only at the point at which it’s required. If functionality which uses that library is used rarely then it makes little sense incur the overhead of an additional HTTP request or data transfer on page load.

We can dynamically load any JavaScript and add it to the document with the following function.

Making a dynamic request

  1. function loadScript(sScriptSrc) {
  2. var oHead = document.getElementById('head')[0];
  3. var oScript = document.createElement('script');
  4. oScript.type = 'text/javascript';
  5. oScript.src = sScriptSrc;
  6. oHead.appendChild(oScript);
  7. }

This approach isn’t without problems though. The request will load asynchronously which means that any JavaScript which depends on code returned by the request may continue to run before the request completes resulting in errors.

Example 1 – Ordered loading

Loads JSL which includes jQuery Core and jQuery UI. This example takes into consideration the need to load jQuery Core as soon as possible and prepares for inline and other external scripts that may depend on jQuery. The script block needs to appear high in the HTML DOM and before other scripts in order to prevent race conditions on included scripts.

so we will require a good dynamic javascript loader and dependency manager . currently i am using jsl.load

more links :






Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s