A PDF editor moves a large file into a Web Worker to keep parsing off the main thread. The first message still pauses the interface: passing a buffer without a transfer list copies its bytes as part of structured cloning. For large files, that copy can be expensive.
Transferring an ArrayBuffer changes ownership instead. The worker receives the buffer, and the sender's buffer becomes detached. Its byteLength becomes zero. Plan for that ownership change before wiring it into a preview or export flow.
Transfer the file bytes
This example uses a module worker and reads a selected file into memory. Serve these files over HTTP from the same origin, rather than opening the HTML file directly.
<input id = "file" type = "file" accept = "application/pdf" > <output id = "status" ></output> <script type = "module" src = "./main.js" ></script>
Enter fullscreen mode
Exit fullscreen mode
// main.js const worker = new Worker ( './pdf-worker.js' , { type : 'module' } ) ; const status = document .…