On-Demand JavaScript

Example of pattern used in the pattern which loads a JavaScript file across domains (and over SSL).

Note that this maintains integrity even if the remote script is slow to download to the client.

  1. Click here to use a function from the additional script.
    Try it before clicking the link below.
  2. Click here to pull in JavaScript file (Nationwide Financial's Sales & Service Center's formUtils.js) which was not included initially.
    Note: This can take a while to load...
    Try clicking it more than once (after it has loaded).
  3. Now try step #1 again. It works!
  4. Now try step #2 again. It can tell it doesn't need to load the script again!

See the On-Demand JavaScript page at AjaxPatterns.org for a more thorough treatment of this approach.

See this Dynodes library discussion for more info.