Your page is freezing because of this. Here is how to fix it.
End secret sprawl across your stack
Infisical is your one source of truth for every secret, key, & credential. Open source and runs on Postgres. Trusted by Hugging Face, Lucid, and more.
Hey everyone,
You have a long, boring task running in your app. The page freezes. The user stares at a blank screen. They leave.
The problem is JavaScript runs everything on one thread. Heavy work blocks everything else.
There is a fix. And most devs have never used it.
The Code: Web Workers
// worker.js
self.onmessage = (e) => {
const result = heavyCalculation(e.data);
self.postMessage(result);
};
// main.js
const worker = new Worker("worker.js");
worker.postMessage(myData);
worker.onmessage = (e) => {
console.log("Done!", e.data);
};
The heavy work runs in the background. Your UI stays smooth. The user never notices a thing.
Why this is a win:
- Your page never freezes. The worker runs on a separate thread, completely away from the UI.
- Perfect for real use cases. Parsing large files, processing images, running calculations. Anything slow belongs in a worker.
- Simple to set up. Two files, a few lines each. No libraries, no configuration.
One thing to keep in mind:
Workers cannot access the DOM. They also cannot share data directly with the main thread. When you send something via postMessage, the data is copied, not shared. Keep your messages small and only pass what the worker actually needs.
Happy coding!
Marko