SiteTidy
HomeGuidesCore Web Vitals (Part 6): JavaScript, Hydration and Third-Party Performance
Performance

Core Web Vitals (Part 6): JavaScript, Hydration and Third-Party Performance

Reduce JavaScript's impact on LCP and INP with route-level code splitting, partial hydration, better scheduling, smaller dependency graphs, worker offloading and a hard look at third-party scripts.

Published on August 15, 2026Updated August 31, 2026
Core Web Vitals (Part 6): JavaScript, Hydration and Third-Party Performance

JavaScript has a performance property that images do not: after you download it, you still have to parse it, compile it and run it.

That makes “our bundle is only 300 KB compressed” an incomplete argument.

Three hundred kilobytes of JavaScript on a high-end desktop and fibre connection can feel trivial. The same application on a mid-range phone may spend meaningful time parsing and executing it, while the main thread is also trying to render content and respond to the user.

JavaScript can hurt both sides of Core Web Vitals:

  • it can delay LCP by preventing important content from being rendered or discovered;
  • it can hurt INP by occupying the main thread when the user interacts.

The goal is not “zero JavaScript”. The goal is only shipping and executing JavaScript where JavaScript creates enough user value to justify its cost.

Start with execution, not bundle-size screenshots

Bundle size is useful because bytes correlate with download and often with parse/compile cost.

But two bundles of the same compressed size can behave very differently.

One might contain mostly definitions and small modules. Another may initialise a charting engine, walk the DOM, register dozens of listeners and synchronously process a large data structure on startup.

Use DevTools Performance and coverage/bundle analysis to answer:

  • what gets downloaded?
  • what gets executed during startup?
  • how long does execution take?
  • which tasks block the main thread?
  • how much code is unused on this route?
  • what runs before LCP?
  • what runs around slow interactions?

Optimise behaviour, not just the webpack/Vite report.

Route-level code splitting should be normal

A user opening /pricing does not need the code for an authenticated analytics dashboard.

Modern bundlers/frameworks make route splitting relatively straightforward. Use it.

Conceptually:

const ReportBuilder = () => import('./ReportBuilder.js');

or framework-specific lazy/dynamic imports can keep expensive features out of the initial route bundle.

But code splitting has a failure mode: hundreds of tiny sequential chunks.

A waterfall of module requests can be worse than a sensibly grouped bundle, especially when the chunks are discovered late.

Split around meaningful application boundaries, then inspect the actual network/execution result.

Component-level lazy loading should follow likelihood of use

Good lazy candidates:

  • a rich editor opened from a button;
  • a charting package below the fold;
  • an admin-only modal;
  • a code editor on a secondary tab;
  • a large export/report builder.

Poor lazy candidates:

  • the component containing your LCP content;
  • primary navigation needed immediately;
  • functionality almost every visitor uses within the first second.

Lazy loading is a scheduling decision, not an automatic optimisation.

Tree shaking cannot rescue a dependency you initialise badly

Modern build tools can remove unused exports under the right conditions, but dependency choice still matters.

Ask:

  • are we importing the entire utility library for two functions?
  • are locale datasets bundled globally?
  • does the date library include functionality we never use?
  • is a 200 KB visualisation package justified for one tiny sparkline?
  • can a platform API replace this dependency?

Do not spend a week hand-optimising your own 8 KB module while a forgotten vendor SDK contributes hundreds of kilobytes and multiple long tasks.

Server rendering is not the same as less JavaScript

SSR can improve initial content availability, but a common architecture does this:

  1. render the entire page on the server;
  2. send the HTML;
  3. send the entire application JavaScript;
  4. execute it again on the client to hydrate everything.

The user gets early pixels but may still pay a large hydration cost.

That can produce a page that looks interactive before it is comfortably interactive.

SSR is a delivery technique. You still need a client-JavaScript strategy.

Partial/selective hydration: keep static content static

Many pages contain far more content than interaction.

An article page might need JavaScript for:

  • search;
  • a copy button;
  • a newsletter form;
  • maybe a table-of-contents widget.

It does not necessarily need the entire article body represented as a hydrated client component tree.

Architectures such as islands/partial hydration let the static majority remain HTML while specific interactive components receive JavaScript.

This can reduce:

  • startup bundle size;
  • hydration work;
  • main-thread contention;
  • the amount of application state the browser must maintain.

Do not hydrate prose just because your framework can.

Hydrate by priority, not all at once

Interactive content above the fold deserves different treatment from a complex widget 2,000 pixels down the page.

Where your framework supports it, consider:

  • immediate hydration for essential controls;
  • visible/viewport hydration for below-fold widgets;
  • interaction-triggered hydration for rarely used UI;
  • idle/background scheduling for low-priority enhancements.

The exact API differs between Astro, React-based frameworks, Vue/Nuxt and others. The design principle is the same: startup is a scarce resource.

Avoid doing expensive work during module initialisation

This runs as soon as the module executes:

const index = buildSearchIndex(hugeDataset);

export function search(query) {
  return index.find(query);
}

If search is optional, you have just charged every visitor for it during startup.

Prefer initialising expensive optional features when they are needed, or building data structures server-side/build-time where possible.

Module import should not casually mean “perform half a second of CPU work”.

Main-thread scheduling matters

Low-priority work should not routinely block input.

Examples:

  • analytics batching;
  • precomputing optional views;
  • non-critical UI enhancement;
  • expensive client cache maintenance.

Break large work into chunks and yield where appropriate so the browser can process input and render between them.

Newer scheduling primitives can help in supported environments, but the principle does not depend on one API: cooperate with the event loop instead of assuming your task owns the main thread until it is finished.

Workers are valuable for the right CPU work

A Web Worker can perform computation without occupying the main UI thread.

Strong candidates include:

  • large data transforms;
  • client-side search/indexing;
  • compression/decompression;
  • parsing large files;
  • expensive calculations.

Weak candidates include tiny operations where messaging overhead and architectural complexity exceed the work itself.

Workers also cannot directly update the DOM. You still need a main-thread handoff to render results.

Use them to isolate substantial computation, not as performance decoration.

Third-party JavaScript: build a budget and an owner list

Third parties are where many performance programmes lose discipline.

First-party code gets code review. A tag manager then loads:

  • analytics;
  • heatmaps;
  • session replay;
  • advertising pixels;
  • chat;
  • experimentation;
  • affiliate tracking;
  • social widgets;
  • consent tooling;
  • five things nobody remembers adding.

Every one of those scripts can download, execute, allocate memory, observe the DOM and schedule work.

Create an inventory:

Script Business owner Routes Startup required? Transfer Main-thread cost Keep?
Analytics Growth All Maybe … … Yes
Chat Support Support/pricing No … … Review
Old heatmap Unknown All No … … Remove

If nobody owns a third-party dependency, that is already useful information.

Delay third parties according to their purpose

Not everything needs to initialise before LCP.

A support chat widget can often wait until the main page is usable. A survey tool may only be needed after a user has spent time on the page. A video player can wait for interaction.

Be careful with consent/legal requirements and analytics semantics, but challenge the default assumption that every vendor belongs in the critical path.

Tag managers do not make code free

Moving a script into a tag manager changes how it is deployed, not what the browser executes.

In fact, a poorly governed tag manager can make performance harder to reason about because code changes outside the normal application release process.

Treat tag-manager configuration as production code:

  • ownership;
  • review;
  • environments;
  • versioning;
  • performance monitoring;
  • removal process.

Hydration mismatches can waste work and create instability

If server-rendered markup differs from what the client expects, frameworks may warn, discard work or rerender portions of the page.

Causes include:

  • using current time/random values during render;
  • client-only feature detection changing markup;
  • inconsistent locale/timezone output;
  • data changing between server render and hydration;
  • invalid HTML structure.

Besides correctness problems, this can create extra rendering work and visual instability.

Keep server/client output deterministic where hydration expects it.

Large JSON payloads are JavaScript work too

Frameworks often serialise page data into HTML so the client can hydrate.

A page may have a modest JS bundle but embed 800 KB of JSON state, which then has to be downloaded, parsed and retained.

Inspect document payloads and hydration data.

Do not send the browser every field from a backend object merely because the server already has it.

Shape data for the UI.

Avoid duplicate work across server and client

If the server already transformed a dataset into the exact model needed for rendering, ask why the client immediately recomputes the same transformation during hydration.

Likewise, do not fetch data again on mount if equivalent fresh data is already embedded in the response unless revalidation is intentional.

Performance improves when the architecture has clear ownership of work.

A JavaScript performance workflow

1. Start with RUM

Find routes with poor INP or LCP/render-delay patterns.

2. Record a constrained-device trace

Inspect startup and the problematic interaction.

3. Find long tasks and expensive call stacks

Identify actual CPU consumers.

4. Inspect bundles and coverage

Find code delivered to the route but unused.

5. Separate essential from optional startup work

Defer, lazy-load or remove the optional work.

6. Reduce hydration scope

Keep static content out of the client runtime where possible.

7. Audit third parties

Remove/delay scripts whose value does not justify their cost.

8. Re-test on representative hardware

Then verify with field telemetry after release.

Inspect what the browser is really being asked to do

Use SiteTidy for the broad page audit, then pair it with bundle analysis, coverage and Performance traces to turn "too much JavaScript" into specific engineering work.

Run Free Audit →

Common JavaScript performance mistakes

Chasing compressed bundle size alone

Execution cost matters.

Splitting every component into its own chunk

Chunk waterfalls and overhead can replace one problem with another.

SSR-ing everything and assuming the job is done

Hydration may still be enormous.

Loading analytics “async” and assuming it cannot affect INP

Async affects loading dependency behaviour. The code still eventually runs on the main thread unless isolated elsewhere.

Memoising everything

Memoisation can add complexity and memory overhead. Use it for measured expensive work.

Keeping abandoned tags because removing them feels risky

Unowned third-party code is itself a risk.

Production checklist

  • split code around meaningful route/feature boundaries;
  • lazy-load expensive optional UI;
  • keep LCP-critical content out of late client-only paths;
  • minimise client hydration scope;
  • defer below-fold/optional hydration;
  • avoid heavy module-initialisation work;
  • remove unused dependencies and oversized imports;
  • inspect serialised hydration/page data;
  • avoid duplicate server/client computation;
  • break up unavoidable long tasks;
  • use workers for substantial suitable computation;
  • inventory and govern third-party scripts;
  • delay third parties that do not belong in the critical path;
  • test on CPU-constrained hardware;
  • monitor route/interaction performance in RUM by release.

JavaScript is one of the web’s greatest strengths. Performance problems appear when we treat execution as free simply because the file downloaded successfully.

Part 7 moves underneath the component layer to CSS, fonts and the rendering path — the resources that determine how quickly the browser can turn HTML into stable pixels.

Ready to audit your site?

Put this guide into practice immediately using our free tools.

Browse 180+ Free Tools