EFWS home | examples | stevesouders.com
Couple Script Defer
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.

In this example, the script is loaded using the Script Defer technique.

<script defer src="menu.js" type="text/javascript"></script>

The DEFER attribute is part of the HTML 4 specification, but it is only supported in IE, and even there execution order is not preserved, resulting in undefined symbol errors. In other browsers, it will have no effect and the external script will still block downloads and rendering in the page.

Takeaway: If you use these asynchronous script loading techniques, you need to use a coupling technique to avoid undefined symbol errors.

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