Accepting selected projects for Q2 2024 Check availability
SERVER 02SYSTEM ONLINELAST SYNC: 03:17:44RSS_FEED.XML — PARSE WARNING
HALF ASSEDTECHNICAL NOTES_
EST. 2009ISSUE 04.2BEST VIEWED AT 1024 × 768
TECHNICAL NOTES / TECHNICAL NOTES / JAVASCRIPT / RECORD 13acbd
[JAVASCRIPT]NOTE

Structuring browser JavaScript with AMD

POSTED: 09.10.2012AUTHOR: ADMIN6 MIN READCOMMENTS: 0

As browser applications grow, global script order becomes difficult to reason about. AMD loaders such as RequireJS make dependencies explicit, but production delivery still requires a planned build.

Define narrow modules

Give each module a clear return value and declare its dependencies rather than reading mutable globals. Keep DOM startup separate from reusable data and formatting logic so modules can be tested without a complete page.

Optimise for production

Use the loader optimiser to combine stable dependency groups and minify the result. Preserve source maps or unminified release artefacts for diagnosis, and verify that dynamic module paths are included.

Control initialisation

Load only the entry point required by the template and initialise after its DOM is available. Watch for plugins that conceal synchronous work or create serial requests after the main bundle has completed.

BUILD CHECK

A dependency graph that works through dozens of local requests may still need bundling to perform acceptably over a high-latency connection.