Lewati ke konten
← Back to Notes

2 November 2026 · 4 min read

As much JavaScript as needed, not as much as possible

From zero hydration to measured interaction: menus, filters, contents, and validation need JavaScript. The cost is 30—250 ms TBT at 1.8 s LCP.

Contents
  1. Why hydration was switched off
  2. What actually needs JavaScript
  3. The numbers and their limits

Why hydration was switched off

This site is almost entirely text and images. No cart, no state that has to live in the browser. The first version therefore used “csr = false”: SvelteKit sent correct HTML without 50 KB of JavaScript to reattach a DOM that was already correct.

The result was a stable 100 for performance, accessibility, best practices, and SEO. Total Blocking Time was zero because there was no hydration work. Navigation used plain links, forms used form actions, and every page stayed readable when JavaScript failed to load.

The limit appeared when the site owner asked for a more interactive experience: a mobile menu, project filtering, a table of contents that follows reading position, and form validation before submission. All of them need browser state. Forcing them without JavaScript would produce a more fragile solution, not a faster one.

What actually needs JavaScript

Hydration came back, but only for four things: a mobile navigation menu with focus handling and scroll lock, project filters that recount results, a table of contents that marks the active section, and per-field contact validation. No animation library or global store was added.

Visual effects stay in CSS. Sections appear through an eleven-line IntersectionObserver, not a scroll library. The menu uses existing elements and ARIA attributes. The form still submits without JavaScript because it uses method="POST" and a form action; hydration only adds feedback before the page navigates.

CSP is tightened with a per-request nonce instead of “unsafe-inline”, so the hydration script SvelteKit injects is allowed while foreign scripts are not. Turnstile loads only on the contact page. There is no third-party JavaScript on the home page.

The numbers and their limits

In production, LCP sits at 1.8 seconds under Lighthouse mobile simulation. Total Blocking Time is 30 ms on a stable run and has reached 250 ms on a cold run — this is the hydration cost, now visible instead of hidden. Performance moves between 95 and 99; accessibility, best practices, and SEO stay at 100.

The trade-off is explicit: text pages no longer get zero TBT, and a score of 100 is no longer guaranteed on every run. In exchange, visitors get a menu that closes with Escape, filters that answer immediately, a table of contents that follows reading position, and a form that explains errors before submission.

If TBT rises again, the next step is not removing interaction but selective hydration: text-only pages return to “csr = false”, while pages that need state keep JavaScript. Decisions are measured, not assumed.