Use web workers for heavy parsing
Run a CPU-heavy parsing job such as CSV in a Web Worker and send the rows back with postMessage, so the page keeps responding while it works.
Parsing a large CSV or Markdown file on the main thread blocks input until it finishes. A worker has its own thread, so the page stays interactive.
self.onmessage = ({ data: text }) => {
const rows = text
.trim()
.split('\n')
.map((line) => line.split(','));
self.postMessage({ count: rows.length, first: rows[0] });
};const worker = new Worker(new URL('./csv-worker.js', import.meta.url));
worker.onmessage = ({ data }) => {
console.log(`parsed ${data.count} rows, first:`, data.first);
worker.terminate();
};
worker.postMessage('id,name\n1,Ada\n2,Grace');parsed 3 rows, first: [ 'id', 'name' ]new URL('./csv-worker.js', import.meta.url) is the form that bundlers such as Vite recognise and package as a separate file. Data goes in and out by postMessage, which copies it; for large binary data, transfer an ArrayBuffer in the second argument to move it with no copy.
Workers cannot touch the DOM, and each one costs memory and start-up time, so keep a long-lived one for repeated jobs instead of creating one per task. Call terminate() when done. This split on commas ignores quoted fields, so use a real CSV parser in practice. See Web Workers API.