Transferable Objects: Zero-Copy Data for Web Workers

Transferable Objects move resource ownership between contexts, like threads, instead of copying data. This enables fast, 'zero-copy' transfers for large memory blocks. Use it with `postMessage()` to send an `ArrayBuffer` to a Web Worker.
Transferable Objects move resource ownership between JavaScript contexts, like the main thread and a Web Worker, instead of copying data. This enables fast, 'zero-copy' operations for large resources like an `ArrayBuffer`. This is key for performance, avoiding a slow copy that would block the main thread. It's used with `postMessage()` and `structuredClone()`. The footgun: the original object is neutered and becomes unusable. You must also transfer the resource owner (the `.buffer`), not just a typed array view on it.
Read the original → developer.mozilla.org
- #web workers
- #performance
- #javascript
- #web apis
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.