Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

Subscribe to the newsletter

Get new articles and course lessons delivered to your inbox. No spam, unsubscribe anytime.

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
PerformanceJune 27, 20264 min read

Web Workers for JSON Parsing: Stop Blocking the Main Thread

Web Workers for JSON parsing can drastically improve your app's performance. Learn how to offload data serialization to keep your main thread responsive.

Web WorkersPerformanceJavaScriptJSONTBTFrontendWeb PerformanceWeb Vitals

When you're building data-intensive dashboards, that familiar "frozen" UI state usually comes down to one culprit: the main thread is busy doing work it shouldn't be. Last month, while optimizing a data-heavy reporting tool, I realized we were parsing a 4MB JSON payload on the main thread. The result was a spike in Total Blocking Time (TBT) that hovered around 500ms—an eternity for a user trying to click a sort button.

If you’ve ever noticed your app stuttering when fetching large datasets, you're likely seeing the cost of synchronous JSON.parse(). Since JavaScript is single-threaded, that block of CPU-intensive work prevents the browser from painting frames or responding to clicks.

Offloading JSON Parsing to Web Workers

The fix isn't necessarily to fetch less data, but to move the heavy lifting out of the critical path. By moving your data serialization and parsing logic to a Web Worker, you effectively hand off the heavy lifting to a background thread. The main thread stays free to handle user interactions while the worker crunches the JSON in the background.

I initially tried to just wrap the fetch call inside the worker, but I hit a wall with data transfer overhead. Passing large objects back and forth between threads can actually create new performance bottlenecks if you aren't careful about how you structured the message passing.

The Architecture of Offloading

To implement this effectively, think of your Web Worker as a dedicated data processing service. Instead of sending the raw response, the worker should handle the fetch, parse the JSON, and then return a processed, lightweight version of the data.

JAVASCRIPT
// worker.js
self.onmessage = async (e) => {
  const { url } = e.data;
  const response = await fetch(url);
  const data = await response.json();
  
  // Perform heavy data transformation here
  const processed = data.map(item => ({ id: item.id, val: item.value * 2 }));
  
  self.postMessage(processed);
};

When you move this logic, you’ll notice your main-thread performance metrics begin to stabilize. The main thread only receives the final, ready-to-render object rather than waiting for the entire parsing process to complete.

Why JSON Parsing Hits TBT So Hard

It’s easy to assume JSON.parse() is cheap because it’s a native method. However, it’s a synchronous, blocking operation. When you parse a massive array of objects, the browser cannot switch to rendering tasks until the parser finishes.

As I discussed in my previous work on Web Performance: Preventing Main-Thread Congestion with Workers, keeping the main thread clear is non-negotiable for high-end user experiences. If you are already working with complex server-side payloads, you might also want to look at Next.js Data Serialization: Managing State in Server Actions to ensure your data transfer is as efficient as possible before it even reaches the client.

StrategyMain-Thread ImpactComplexityBest For
Synchronous ParseHighLowSmall payloads (< 100KB)
Web Worker ParseNegligibleMediumLarge datasets / Heavy transforms
Streaming ParseLowHighReal-time, infinite-scroll data

Avoiding the "Message Passing" Trap

A common mistake I see is passing massive objects back and forth via postMessage. This triggers a "structured clone" algorithm, which can be just as slow as the original parsing if the object is complex enough.

If your data is truly massive, use Transferable Objects. Instead of cloning the data, you transfer the ownership of the memory buffer from the worker to the main thread. This makes the transfer nearly instantaneous, regardless of the size of the data.

Flow diagram: Main Thread → Request URL Web Worker; Web Worker → Fetch Data Network; Network → Raw JSON B; Web Worker → Parse & Transform B; Web Worker → Transfer Buffer A; Main Thread → Render UI A

Moving Forward

Using Web Workers for JSON parsing isn't a silver bullet for every performance issue, but it’s a standard move for data-heavy applications. I’ve found that the biggest gain isn't just the raw speed—it’s the reliability of the interaction. When the main thread isn't busy parsing, the user's click always feels snappy.

Next time you're profiling your app, look at the "Long Tasks" in your browser's performance tab. If you see JSON.parse blocks, don't just optimize the data structure. Move the work. I’m still experimenting with how much of this can be offloaded to Edge functions to avoid sending the raw data to the client entirely, but for now, the worker approach has cut my TBT by about 40% on our main dashboard. It's not perfect, but it's consistent.

Back to Blog

Similar Posts

PerformanceJune 26, 20264 min read

Web Performance: Preventing Main-Thread Congestion with Workers

Web Performance starts with a responsive main thread. Learn how to use Web Workers and MessageChannel to offload heavy tasks and improve your Core Web Vitals.

Read more
PerformanceJune 22, 20264 min read

Third-Party Script Optimization: Offloading Scripts with Partytown

Master third-party script optimization using Partytown and Web Workers. Learn how to stop main thread blocking and keep your site fast and responsive.

Read more
Close-up of colorful CSS code lines on a computer screen for web development.
PerformanceJune 21, 20264 min read

Web Workers and OffscreenCanvas for Jank-Free UI Performance

Master Web Workers and OffscreenCanvas to offload heavy rendering tasks from the main thread. Learn how to keep your UI responsive and hit your performance budget.

Read more