New researchTechnical SEO & AI Search · 2027Explore the framework

First-party JavaScript performance: reduce main-thread work

Find expensive code you own, from large startup bundles to slow event handlers, and prioritize fixes using field INP and browser performance traces.

Part of the Core Web Vitals series. For the full picture, start with Core Web Vitals: what they are, how they affect SEO and how to improve them.

When a button waits before responding, the culprit is not always an analytics tag. Your own hydration, state updates, search filtering and UI handlers may be doing more work than the browser can fit between frames. A first-party JavaScript performance audit finds the work you can change directly.

How do you improve first-party JavaScript performance?

Measure a user-facing symptom first, then trace the code path. Google’s INP optimization guide divides a slow interaction into input delay, processing time and presentation delay. Long startup tasks may delay the handler; a heavy callback may process for too long; a large DOM update can delay the next paint. The right fix depends on which part dominates.

Symptom in a trace Likely first-party cause First experiment
Long tasks during initial load Bundle parsing, hydration or initialization Remove unused code or delay noncritical initialization
Slow click handler Synchronous filtering or computation Do less in the handler; split work into tasks
Delay after handler Large render or layout update Reduce affected DOM and style work

This article focuses on code your team ships. The third-party script audit is for vendor tags; the INP guide explains the metric itself.

Where do you find the slow work?

Begin with field data by template and device. If real-user INP is poor on product pages, reproduce a representative interaction such as selecting a variant or opening a filter. Record a browser Performance trace, then identify long tasks, script evaluation, event callbacks and rendering work around that interaction. Google notes that script evaluation can block the main thread even after the file has downloaded (web.dev).

Use a production build for tests. Development bundles and framework diagnostics can distort timings. Repeat the same interaction a few times on a lower-powered device profile and compare before and after traces. A single Lighthouse score is useful for clues, not proof of a real-user improvement.

Which fixes should come first?

Remove work that delivers no current-page value. Check whether a route loads code for features the visitor cannot use, whether state is initialized twice, and whether a handler recalculates a full catalogue when one item changes. Split large bundles by route or feature when this reduces startup evaluation. Keep critical interaction code available; indiscriminate deferral can merely move the delay to the first click.

For complex handlers, update visible UI promptly and break later work into smaller tasks. Google’s INP guidance explains yielding to the main thread so rendering and other interactions can proceed. Avoid replacing a clear, short operation with many scheduled tasks unless the trace shows a benefit.

How do you know the change worked?

Compare lab traces for the same action, then watch field INP on the affected template. Check that LCP and CLS did not regress through new loading or layout behavior. The Core Web Vitals audit explains why field and lab results can differ. Document the interaction, device, route and release date, not just a before-and-after score.

First-party JavaScript checklist

  • Identify slow real-user interactions and affected templates
  • Trace startup tasks, event callbacks and presentation delay
  • Remove unused code before tuning small functions
  • Split route-specific and noncritical startup work
  • Keep user-visible updates short and avoid oversized DOM changes
  • Test a production build on a constrained device
  • Watch field INP and check LCP/CLS after release

The best JavaScript optimization is often less work, not a more elaborate scheduler.

Frequently asked questions

Does a small JavaScript download guarantee a fast page?

No. Download size is only one cost; parsing, executing and interaction callbacks also occupy the main thread. Inspect browser tasks and real-user responsiveness before choosing a fix.

Is first-party JavaScript different from third-party scripts?

Yes. First-party code is the application bundle and logic your team owns; third-party tags come from vendors. Both can delay interactions, but ownership changes how you prioritize and deploy fixes.

Should I defer every script to improve INP?

No. Deferring noncritical startup work can help, but code needed for an early interaction must still be ready. Measure the actual interaction and keep its handler brief.

Can Lighthouse replace field INP data?

No. Lighthouse provides lab diagnostics under simulated conditions, while INP is a field measure of real interactions. Use lab traces to explain a field problem, then monitor users after the fix.

· Founder, Crawlens

Dien builds Crawlens, a desktop crawler for technical SEO audits, and writes about the checks it runs: crawling, indexing, rendering and Search Console data.

Audit your own site with Crawlens

Crawl, run 70 checks, and see them next to Search Console and Core Web Vitals data.

Download free for Windows