EFWS home | examples | stevesouders.com
loadScript
Examples ▼
Was the script loaded without blocking?
Was execution order preserved?

This page contains an external script and some inlined code that depends on the external script. The external script, menu.js, is loaded asynchronously. The inlined code's init function calls EFWS.Menu.createMenu(), a function defined in the external script. Because of this dependency, the inlined code must be coupled with the external script so that the execution order is preserved: the external script is loaded, parsed, and executed before the inlined code.

This example demonstrates the general solution for loading a single script: EFWS.Script.loadScript. This function uses the Script DOM Element for loading the script asynchronously, and the Script Onload technique for coupling the inlined code with the external script to preserve execution order.

EFWS.Script.loadScript("menu.js", init);

This technique avoids the blocking behavior of scripts across all browsers.

home | contact SteveBlackbuck AntelopeThis is the companion website for Even Faster Web Sites by Steve Souders.