WebAssembly (WASM) for High Performance Apps · Lekcja

Jak WASM działa w przeglądarce

Zrozum model wykonywania WebAssembly: dowiedz się, jak silnik kompiluje, tworzy instancję i uruchamia WASM obok JavaScriptu.

Lekcja 4 z 413 kroki

Jak WASM działa w przeglądarce to bezpłatna lekcja WebAssembly (WASM) for High Performance Apps na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej WebAssembly (WASM) for High Performance Apps, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs WebAssembly (WASM) for High Performance Apps zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

WASM Is Not Interpreted Bytecode... Quite

WASM ships as a compact binary that the browser engine turns into fast machine code — compiled and run near native speed, not interpreted line-by-line. Let's trace its path.

The .wasm Binary

A WASM module is a .wasm file: a stack-based binary with sections for types, functions, memory, and exports. WAT is its readable text twin.

(module
  (func (export "add") (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.add))

Step 1: Fetch the Module

Step 1: the browser fetches the binary, usually with fetch, reading it into an ArrayBuffer.

const response = await fetch('add.wasm');
const bytes = await response.arrayBuffer();

Step 2: Compile

Step 2: the engine validates and compiles those bytes into machine code, producing a WebAssembly.Module.

const module = await WebAssembly.compile(bytes);

Step 3: Instantiate

Step 3: instantiation creates a live WebAssembly.Instance with its own memory and exported functions, ready to call.

const instance = await WebAssembly.instantiate(module, {});
const add = instance.exports.add;

Streaming Compilation

Streaming compilation compiles while downloading — no buffering the whole file first. Use instantiateStreaming for the fastest start.

const { instance } = await WebAssembly.instantiateStreaming(
  fetch('add.wasm'), {}
);

Calling Exported Functions

Once instantiated, WASM exports behave like ordinary JS functions — just call them with arguments and get results back.

const result = instance.exports.add(2, 3);
console.log(result); // 5

Linear Memory

Linear memory is one contiguous, resizable ArrayBuffer that both JS and WASM read and write. It's how larger data crosses the boundary.

const mem = new Uint8Array(instance.exports.memory.buffer);

The Sandbox

WASM runs in a strict sandbox: no direct DOM, network, or file access — it can only call functions JS imports in. That's what keeps it safe and portable.

Importing JS Into WASM

To give WASM capabilities, pass an imports object at instantiation. WASM can then call those JS functions — the only way it reaches the outside world.

const imports = { env: { log: (x) => console.log(x) } };
const { instance } = await WebAssembly.instantiate(bytes, imports);

Putting It Together

The lifecycle in one line: fetch, compile, instantiate, call. Data crosses via linear memory, and JS controls the sandbox through imports.

Quick Check

Which API both compiles and instantiates a WASM module as it downloads?

Recap

Recap: a binary is fetched, compiled, and instantiated; streaming overlaps the two; exports act like JS functions sharing linear memory; the sandbox stays safe via imports.

Bezpłatny start

Ucz się WebAssembly (WASM) for High Performance Apps dzięki korepetycjom AI — za darmo

Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.

Kursy
12
Lekcje
48

Często zadawane pytania

Czy lekcja „Jak WASM działa w przeglądarce” jest bezpłatna?

Tak — pełny tekst „Jak WASM działa w przeglądarce” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu WebAssembly (WASM) for High Performance Apps, przejdź na CoddyKit PRO. Kurs WebAssembly (WASM) for High Performance Apps zawiera 4 lekcji w sumie.

Co nauczysz się w „Jak WASM działa w przeglądarce”?

Zrozum model wykonywania WebAssembly: dowiedz się, jak silnik kompiluje, tworzy instancję i uruchamia WASM obok JavaScriptu. Ćwiczysz WebAssembly (WASM) for High Performance Apps z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć WebAssembly (WASM) for High Performance Apps?

Nie wymagamy żadnego doświadczenia. WebAssembly (WASM) for High Performance Apps w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Jak WASM działa w przeglądarce”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji WebAssembly (WASM) for High Performance Apps?

Tak. Każda lekcja WebAssembly (WASM) for High Performance Apps zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Czym jest WebAssembly (WASM)?
  2. Dlaczego warto używać WASM? Najważniejsze zalety
  3. Ekosystem WASM i narzędzia
  4. Jak WASM działa w przeglądarce
← Powrót do WebAssembly (WASM) for High Performance Apps