kb/data/developer.mozilla.org/en-US/docs/Games/Techniques/Async_scripts-0.md

20 KiB
Raw Blame History

title chunk source category tags date_saved instance
Async scripts for asm.js - Game development | MDN 1/1 https://developer.mozilla.org/en-US/docs/Games/Techniques/Async_scripts reference web, html, css, javascript, documentation 2026-05-05T05:21:38.111979+00:00 kb-cron

MDN HTML HTML: Markup language

HTML reference

HTML guides

Markup languages

CSS CSS: Styling language

CSS reference

CSS guides

Layout cookbook

JavaScriptJS JavaScript: Scripting language

JS reference

JS guides

Web APIs Web APIs: Programming interfaces

Web API reference

Web API guides

All All web technology

Technologies

Topics

Learn Learn web development

Frontend developer course

Learn HTML

Learn CSS

Learn JavaScript

Tools Discover our tools

About Get to know MDN better

Blog

  1. Game development
  2. Techniques for game development
  3. Async scripts for asm.js

Async scripts for asm.js

Every medium or large game should compile asm.js code as part of an async script to give the browser the maximum flexibility to optimize the compilation process. In Gecko, async compilation allows the JavaScript engine to compile the asm.js off the main thread when the game is loading and cache the generated machine code so that the game doesn't need to be compiled on subsequent loads (starting in Firefox 28). To see the difference, toggle javascript.options.parallel_parsing in about:config.

In this article

Putting async into action

Getting async compilation is easy: when writing your JavaScript, just use the async attribute like so: or, to do the same thing via script: (Scripts created from script default to async.) The default HTML shell Emscripten generates produces the latter.

When is async not async?

Two common situations in which a script is not async (as defined by the HTML spec) are: and Both are counted as 'inline' scripts and get compiled and then run immediately. What if your code is in a JS string? Instead of using eval or innerHTML, both of which trigger synchronous compilation, you should use a Blob with an object URL: The setting of src rather than innerHTML is what makes this script async.

Help improve MDN

Learn how to contribute This page was last modified on Jul 11, 2025 by MDN contributors. View this page on GitHubReport a problem with this content

  1. Games
  2. Introduction 1. Introduction 2. Anatomy
  3. APIs for game development 1. asm.js 2. Canvas 3. CSS 4. Full screen 5. Gamepad 6. IndexedDB 7. JavaScript 8. Pointer Lock 9. SVG 10. Typed Arrays 11. Web Audio 12. WebGL 13. WebRTC 14. WebSockets 15. WebVR 16. Web Workers 17. XMLHttpRequest
  4. Techniques 1. Using async scripts for asm.js 2. Optimizing startup performance 3. Using WebRTC peer-to-peer data channels 4. Audio for Web Games 5. 2D collision detection 6. Tiles and tilemaps overview 7. Using the Gamepad API 8. Image rendering for pixel art
  5. 3D games on the Web 1. Explaining basic 3D theory 2. Building up a basic demo with A-Frame 3. Building up a basic demo with Babylon.js 4. Building up a basic demo with PlayCanvas 5. Building up a basic demo with Three.js 6. GLSL shaders 7. WebXR 8. 3D collision detection 9. Bounding volume collision detection with THREE.js
  6. Implementing game control mechanisms 1. Mobile touch 2. Desktop with mouse and keyboard 3. Desktop with gamepad 4. Other
  7. Tutorials 1. 2D breakout game using pure JavaScript 2. 2D breakout game using Phaser 3. 2D maze_game with device orientation 4. 2D platform game using Phaser
  8. Publishing games 1. Game distribution 2. Game promotion 3. Game monetization

MDN Your blueprint for a better internet.

MDN

Contribute

Developers

Mozilla

Visit Mozilla Corporations not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.