Zero JavaScript is a feature

A reading page should work before its scripts start. Why I disabled the page runtime and kept JavaScript for specific features.

On this page

When I set this site up, I nearly shipped a browser runtime out of habit. Most of my work needs one. But someone reading a post should be able to see the words and follow links before application code starts.

That gave me a starting point. Build the document first, then decide which behaviour needs JavaScript. A runtime is the code a framework keeps running in the browser to manage the page. It should have a job beyond making the setup feel familiar to me.

I started by looking at how much JavaScript pages ship. To understand that cost, I also needed to separate what HTML already gives the browser from the work a framework adds.

Downloading the code is only part of its cost

HTTP Archive's 2024 JavaScript chapter reported these median measurements for mobile pages.

  • 558 KB of JavaScript transferred.
  • 22 script requests.
  • 206 KB of estimated unused JavaScript during page load.

The median payload grew 14% in a year. These are historical measurements from 2024, not numbers I measured on this site.

The unused code needs some care. Code that did not run during the tested page load might run after a click or another action. It does not mean that those bytes never do anything, or that every page can safely delete them. The measurements also do not tell us how much of the payload comes from hydration, analytics or particular features.

Still, sending code has a cost before it does useful work. The browser has to load it, parse it and prepare it to run. JavaScript work can also delay input and rendering when it occupies the browser's main thread, where much of that work happens. Google's explanation of long tasks describes this cost.

That led me to the startup work a reading page might not need at all.

Hydration connects application logic to existing HTML

Suppose a server renders this button.

<button>10</button>

The browser knows it is a button showing 10. It cannot infer that it belongs to a counter or that a click should add one. That behaviour belongs to the application.

With hydration, a framework loads its component code in the browser, initializes the application state and connects its behaviour to the existing HTML. React's hydrateRoot documentation describes attaching React to HTML the server already produced. This can reuse the existing elements. It does not require rebuilding every element from scratch.

The page can therefore show text before a button controlled by the framework is ready to work. The HTML and the application logic arrive through different parts of the loading process.

Miško Hevery, the creator of Angular and Qwik, argued in 2022 that recovering information the server already had is avoidable overhead. He uses overhead to mean work that could disappear while preserving the result. That is an argument about how frameworks start applications, not evidence that every downloaded script is waste.

For a counter, I need the behaviour that changes its value. For an article, the paragraphs and links may already be doing their job. The useful question is how much of the page needs application behaviour.

Frameworks draw that boundary in different places

Astro renders UI components as HTML and CSS by default. A component marked with a client:* directive becomes an interactive island with its own browser code. The surrounding article can stay static. Its islands documentation also describes loading a component when the browser is idle or when it becomes visible.

The idea predates Astro. Katie Sylor-Miller named component islands in 2019, and Jason Miller, the creator of Preact, described the architecture in 2020. What matters to this argument is the boundary. One interactive widget does not require hydrating the whole article.

Qwik preserves information that a hydrating framework would otherwise recover. It writes event references, component information and state into the page so the browser can resume work when needed. Its documentation shows an event reference like this.

<button on:click="./chunk.js#handler_symbol">click me</button>

A small loader listens for events, reads the reference and fetches the required handler. This is resumability. It still involves JavaScript, including the loader. The difference is that it avoids eagerly running the whole application's component code just to recover its structure and event connections.

SvelteKit offers a simpler choice for a page that does not need a component runtime. This site's root layout uses these options.

export const prerender = true;
export const csr = false;

The first generates pages at build time. The second disables SvelteKit's client rendering and hydration for them. Links use normal document navigation. The page options documentation explains this mode.

That does not stop me from explicitly including a separate script. It removes the framework's page runtime. I can still add behaviour to existing HTML without making the framework manage the whole document.

Before adding that behaviour, though, I want to check what the browser already provides.

A document can already be interactive

Links navigate without an application router. The browser already manages their history. A disclosure can open and close with HTML alone.

<details>
  <summary>How this page works</summary>
  <p>The browser opens this section without a script.</p>
</details>

The HTML standard defines this disclosure behaviour. I do not need a component's state and click handler to recreate it.

An HTML form can also submit data without JavaScript. It still needs a server endpoint to process that data. Removing a browser runtime does not give a static site a comment backend for free.

Page transitions were another feature I expected to lose. This site instead opts into the browser's transitions between documents.

@view-transition {
  navigation: auto;
}

Both pages must opt in and share an origin, meaning the same scheme, hostname and port. The browser can then animate the navigation without a JavaScript router. The cross-document view transition documentation explains these conditions. This site's stylesheet also defines the fades and disables them when a reader requests reduced motion.

Support still varies. MDN lists the feature as limited availability. Where it is unsupported, the link performs a normal page load. Reading the destination page does not depend on the animation working.

Native features cover some interactions. For the remaining ones, a small script can improve a document that already works.

Search did not require bringing the page runtime back

The site now has search and combined filters on the writing page. It also has a script that tracks the section being read and scrolls to a chosen heading. These are separate modules, loaded on the pages that use them. SvelteKit hydration remains disabled.

The distinction shows up when JavaScript is unavailable. Readers can still open posts, follow links and browse static topic and reader collections. Typing a query and combining filters in place need the search script. Heading links still reach their sections, while automatic section highlighting needs the article script.

This is progressive enhancement. The document provides the useful starting behaviour, and JavaScript adds something to it. A broken search module should cost the search enhancement, not the ability to read the archive's posts.

The production site also loads PostHog for analytics. That is JavaScript too, and it belongs in any honest account of the page's cost. Disabling hydration does not make third party scripts disappear.

So this site is not literally free of JavaScript today. Its reading experience works without it, and its optional features do not require restoring the framework runtime. That is the part of the original decision I have kept.

The browser runtime has to suit the work

Some applications have much more state to manage. A canvas editor may track selected objects, changes that have not been saved and an undo history. A live dashboard may update many parts of the interface together. A framework can help manage those relationships.

Most of my day job needs browser state. I would not force it into a static document just to reach zero JavaScript. That would move the complexity elsewhere and could make the work harder.

A theme switch or instant search can need browser code too. The size and shape of that behaviour should guide the choice between a small module, an interactive island and a fuller application runtime. There is no need to make that decision once for every kind of page.

For a reading page, I want the words and links to work before any script starts. I can add useful behaviour where it earns its place. If HTML already does the job, I am happy to stop there.