Skip to content
HN On Hacker News ↗

Declarative partial updates  |  Blog  |  Chrome for Developers

▲ 52 points 38 comments by theanonymousone 1d ago HN discussion ↗

Pangram verdict · v3.3

We believe that this document is fully human-written

0 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 5 of 5
SEGMENTS · AI 0 of 5
WORD COUNT 1,630
PEAK AI % 1% · §5
Analyzed
May 24
backend: pangram/v3.3
Segments scanned
5 windows
avg 326 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 1,630 words · 5 segments analyzed

Human AI-generated
§1 Human · 0%

Published: May 19, 2026

The web has long since moved on from the static, document-driven medium that it started as. Modern, rich web apps are used by everyone for many reasons, from communicating, purchasing, consuming rich content, to managing our complex lives.

HTML, despite all its advances, is still delivered in-order in a top-to-bottom fashion with little regard for when content is ready or when the user consumes it. CSS lets you change the ordering of content, but often with significant accessibility side effects. JavaScript lets you manipulate the DOM through various APIs to break free of this somewhat, but those often require verbose syntax or construction of DOM trees to plug into HTML.

Performance is incredibly important for the web, given the client-server nature of the medium but suboptimal choices are often made to circumvent this in-order nature of HTML, which slows down performance. This includes waiting until the whole page is ready or using a heavy framework to deliver components in an asynchronous manner. The popularity of JavaScript frameworks shows that web developers prefer a component-based model rather than the rigid document mental model of the web's origins.

The Chrome team has been considering this problem and has been developing new additions to the web platform under the name of Declarative Partial Updates.

Two new sets of APIs make it easier to deliver HTML in a less linear fashion, whether out-of-order in the HTML document itself or through easier ways to dynamically insert HTML into existing documents using new JavaScript APIs. These are ready for developer testing from Chrome 148 using the chrome://flags/#enable-experimental-web-platform-features flag. Polyfills are also available to let you use these new APIs right away, even in browsers that don't yet support them.

These additions to the web platform are being standardized with positive feedback from other browser vendors and standardization avenues. The relevant standards are in the process of being updated to include these new APIs.

Out-of-order streaming

The first set of changes are new out-of-order streaming APIs using the <template> HTML element and processing instruction placeholders. For example: <div> <?marker name="placeholder"> </div>

...

<template for="placeholder"> Here is some <em>HTML content</em>!

§2 Human · 0%

</template>

Processing instructions have existed in XML for a long time, but have been treated as comments in HTML and ignored. This new API changes that and brings processing instructions to HTML. When the browser sees the <?marker name="placeholder"> processing instructions, it doesn't do anything straight away—much like before—but they can be referenced later.

The <template> element looks up the corresponding processing instructions with a name attribute and replaces the content. In this case, after being parsed, the DOM ends up as: <div> Here is some <em>HTML content</em>! </div>

As well as the <?marker> attribute for replacements, there are also <?start> and <?end> range markers which allow for temporary placeholder content to be shown before the template is processed: <div> <?start name="another-placeholder"> Loading… <?end> </div>

...

<template for="another-placeholder"> Here is some <em>HTML content</em>! </template>

In this case, Loading… shows until the <template> is seen and then is replaced with the new content.

It is also possible to include processing instructions in templates to allow multiple updates: <ul id="results"> <?start name="results"> Loading… <?end> </ul>

...

<template for="results"> <li>Result One</li> <?marker name="results"> </template> ...

<template for="results"> <li>Result Two</li> <?marker name="results"> </template> ...

This results in the following HTML after being parsed: <ul id="results"> <li>Result One</li> <li>Result Two</li> <?marker name="results"> </ul>

With the final processing instruction at the end in case any more <template for="results"> are added to the document later.

Demo

In this video, a basic photo album application is implemented with streaming HTML:

Photo album demo implemented with out-of-order streaming (source)

Both the status and photos are streamed into the HTML after the initial layout.

Use cases

There are many use cases for this out-of-order patching HTML when coupled with streaming HTML:

Island architecture. A common pattern popularized by frameworks like Astro the island architecture where components are hydrated independently on top of static HTML.

§3 Human · 0%

The <template for> API lets static content be handled in a similar fashion directly in HTML. JavaScript frameworks can also use this for more interactive islands or to handle components. Delivery content when it is ready. Thanks to this island architecture, content can be streamed when it is ready rather than held back for content that requires extra processing, for example, a database lookup. While many platforms allow streaming HTML, the in-order nature of HTML means that content is often held back, or by resorting to complex JavaScript DOM manipulations. Now you can deliver the static content while waiting, and then plug in the more expensive content at the end of the HTML stream. HTML can be delivered in the optimal order for page load performance. Taking this one step further, you can change the order even when it is ready. For example, mega menus are a common navigation feature that contain a lot of HTML that the user won't see until the page becomes interactive. This large chunk of HTML can be delivered later in the HTML document to prioritize more important HTML needed for the initial page load. Order is no longer a barrier with HTML.

These are just some use cases, and it is exciting to see what developers use this new API for.

Restrictions and subtleties

The API includes a few restrictions and subtleties to be aware of:

<template for> can only update processing instructions within the same parent element for security reasons. Adding <template for> directly to the <body> element gives it access to the whole document (including the <head>). The <?end> processing instruction is optional and if missing, the content between the <?start> element and the end of the containing element will be replaced. Moving processing instructions after a <template for> has started streaming can also have unexpected consequences with the new content continuing to stream into the old location. Note that when inserting <template for> dynamically with method like setHTML or innerHTML, the "parent" of the template when it is parsed is an intermediate document fragment. That means that inserting HTML using these methods cannot modify existing DOM, and the patching happens "in place" inside the fragment. However, when streaming using methods like streamHTMLUnsafe (that we're about to cover!), there is no intermediate fragment so the templates can replace existing content.

Future potential additions

Some potential future additions that are under consideration include:

Client side includes.

§4 Human · 1%

For example, <template for="footer" patchsrc="/partials/footer.html">. Batching. Client-side, fragment includes could also be extended to handle batching to ensure multiple updates happen at the same time. Preventing overwriting content that will not change. This could be achieved with a content revision number or versioning. This would let state be maintained between route changes or other updates rather than resetting the content. Sanitizing while patching. For example, <template for=icon safe><svg id="from-untrusted-source">...</svg></template>

Polyfill

The Chrome team has released a template-for-polyfill which is available on npm to let sites use this new functionality right away even before this lands in other browsers.

There are some limitations as it cannot directly update browser's HTML parsers, but the most common use cases are covered. Sites should still test in other browsers.

Renewed HTML insertion and streaming methods

Not all content can be delivered in HTML. A second part of the work Chrome is doing in this area involves making it easier to update content through JavaScript.

There already are multiple ways to dynamically inject HTML into an existing document using JavaScript:

setHTML setHTMLUnsafe innerHTML and outerHTML setters createContextualFragment insertAdjacentHTML

However, they all work in slightly different ways with subtleties and differences that developers may not always consider:

Does the new content overwrite or append? Do they sanitize potentially dangerous HTML by escaping <script> tags, for example? If not, should <script>'s run? How do they work with TrustedTypes?

Few developers could honestly look at those APIs and confidently answer those questions for each of them.

A big limitation is that they can only be used for a complete set of HTML known in advance, when there have been calls to allow HTML to be streamed. Practically, this means you need to download the entire content before inserting it, when one of the strong points of HTML is the ability to stream in content right away. This can be worked around in a limited fashion by splitting up payloads or using hacky, deprecated methods like document.write, but they introduce their own problems.

§5 Human · 1%

A new set of Static and Streaming APIs

Chrome has proposed a suite of new APIs and extensions to the existing setHTML and setHTMLUnsafe that cleans this up, as well as introducing streaming functionality:

There are methods to set or replace along with methods to insert content before or after existing HTML. Each method has stream equivalents:

Action Static Streaming Set the HTML contents of the element setHTML(html, options); streamHTML(options); Replace the entire element with this HTML replaceWithHTML(html, options); streamReplaceWithHTML(options); Add the HTML before the element beforeHTML(html, options); streamBeforeHTML(options); Add the HTML as the first child of the element prependHTML(html, options); streamPrependHTML(options); Add the HTML as the last child of the element appendHTML(html, options); streamAppendHTML(options); Add the HTML after the element afterHTML(html, options); streamAfterHTML(options); The new insertion and streaming methods

There are also Unsafe versions we'll cover shortly. While there might appear to be a lot of them (especially when you add in the Unsafe equivalents), the consistent naming convention makes it more obvious what each does compared to the unrelated methods mentioned previously.

The static versions take new HTML as a DOM String argument, along with optional options: const newHTML = "<p>This is a new paragraph</p>"; const contentElement = document.querySelector('#content-to-update');

contentElement.setHTML(newHTML);

The streaming versions work with the Streams API such as with a getWriter(): const contentElement = document.querySelector('#content-to-update'); const writer = contentElement.streamHTMLUnsafe().getWriter();

// Example stream of updating content while (true) { await