kb/data/developer.mozilla.org/en-US/docs/Games/Tools/asm.js-1.md

12 KiB
Raw Blame History

title chunk source category tags date_saved instance
asm.js - Game development | MDN 2/2 https://developer.mozilla.org/en-US/docs/Games/Tools/asm.js reference web, html, css, javascript, documentation 2026-05-05T05:22:10.992352+00:00 kb-cron

What is asm.js, exactly?

It is a very small, strict subset of JavaScript that only allows things like while, if, numbers, top-level named functions, and other simple constructs. It does not allow objects, strings, closures, and basically anything that requires heap allocation. Asm.js code resembles C in many ways, but it's still completely valid JavaScript that will run in all current engines. It pushes JS engines to optimize this kind of code, and gives compilers like Emscripten a clear definition of what kind of code to generate. We will show what asm.js code looks like and explain how it helps and how you can use it. This subset of JavaScript is already highly optimized in many JavaScript engines using fancy Just-In-Time (JIT) compiling techniques. However, by defining an explicit standard we can work on optimizing this kind of code even more and getting as much performance as we can out of it. With standard names and benchmarking, it enables collaborating across multiple JS engines. The idea is that this kind of code should run very fast in each engine, and if it doesn't, it's a bug and there's a clear spec that engines should optimize for. It also reduces the complexity for people writing compilers that want to generate high-performant code on the web. They can consult the asm.js spec and know that it will run fast if they adhere to asm.js patterns. Emscripten, a C/C++ to JavaScript compiler, emits asm.js code to make it run with near native performance on several browsers. Additionally, if an engine chooses to specially recognize asm.js code, there even more optimizations that can be made. Firefox is the only browser to do this right now.

asm.js language summary

asm.js is an intermediate programming language. asm.js has a very predictable performance rate because it is limited to an extremely restricted subset of JavaScript that provides only strictly-typed integers, floats, arithmetic, function calls, and heap accesses. The performance characteristics are closer to native code than that of standard JavaScript. Using a subset of JavaScript asm.js is already supported by major web browsers. Since asm.js runs in a browser it depends heavily on the browser and the hardware.

Help improve MDN

Learn how to contribute This page was last modified on Dec 9, 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.