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.
Why it exists
Sharing large amounts of data between the main thread and a Web Worker is a common performance bottleneck. Copying a multi-megabyte data structure can block the main thread, freezing the UI. Transferable Objects were created to move data between contexts almost instantly, without the cost of copying.
The mental model
Think of a Transferable Object like handing over the physical deed to a house. Instead of building an identical copy of the house for someone else (a slow, expensive copy operation), you simply transfer the ownership document. Once transferred, you no longer own the house and cannot enter it. The resource is moved, not duplicated.
How it works
When you call postMessage() or structuredClone(), you can provide an optional second argument: an array of objects to transfer. For example: worker.postMessage(myObject, [myObject.buffer]). This tells the JavaScript engine to move the ownership of myObject.buffer to the new context instead of copying it. For an ArrayBuffer, this is a fast, zero-copy operation where memory pointers are simply updated. After the transfer, the original object is detached from its resource and becomes unusable; its byteLength will be 0, and any attempt to read or write to it will throw an error.
When to use it
Use Transferable Objects when sending large data to a Web Worker for processing, especially ArrayBuffer, ImageBitmap, or OffscreenCanvas. This is the standard way to perform heavy computations off the main thread without blocking rendering. It's also an efficient option within structuredClone() to avoid deep-copying large binary data.
When not to use it
Do not transfer an object if the original context still needs to access it. If both the main thread and a worker need concurrent access to the same data, you must either accept the cost of copying or use a SharedArrayBuffer for true shared memory.
One canonical example
To send a large file to a worker, you might create a typed array. You transfer its underlying buffer, not the array view itself. The Uint8Array is serializable (can be copied), but its ArrayBuffer is transferable (can be moved).
const uInt8Array = new Uint8Array(1024 1024 8); // 8MB array
console.log(uInt8Array.byteLength); // 8388608
// Transfer the underlying buffer to a worker
worker.postMessage(uInt8Array, [uInt8Array.buffer]);// The original is now neutered
console.log(uInt8Array.byteLength); // 0
Interview question
When using Transferable Objects with Web Workers, what fundamental mechanism optimizes data transfer?
- a.They create a deep clone of the data on the worker thread, offloading the main thread's work.
- b.They transfer ownership of the data's underlying resource, making the original unusable and avoiding a copy.Correct
- c.They compress the data before sending it, reducing the amount of information to be copied.
- d.They allow the main thread and worker to access the same memory region simultaneously for read/write operations.
Why? this is the answer
Transferable Objects optimize data transfer by moving the ownership of a resource, such as an ArrayBuffer, from one context to another, effectively avoiding the costly operation of copying large data. This transfer renders the original resource unusable, unlike deep cloning which creates a separate copy.
Just read this? Test yourself on what you have been reading.
Read the original → developer.mozilla.org
- #web workers
- #performance
- #javascript
- #web apis
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles