API proposed by Chrome: Declarative partial updates
Recorded: May 24, 2026, 3:58 a.m.
| Original | Summarized |
Declarative partial updates | Blog | Chrome for Developers Docs Build with Chrome Web Platform Capabilities ChromeDriver Extensions Chrome Web Store Chromium Web on Android Origin trials Release notes Productivity DevTools Lighthouse Chrome UX Report Accessibility Modern Web Guidance Get things done quicker and neater, with our ready-made libraries. Workbox Puppeteer Experience AI Performance CSS and UI Identity Payments Privacy and security Resources All documentation Baseline web.dev PageSpeed Insights audit The Privacy Sandbox Isolated Web Apps (IWA) Case studies Blog New in Chrome / English Deutsch Español – América Latina Français Indonesia Italiano Nederlands Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어 Sign in Docs More Case studies Blog New in Chrome Build with Chrome Web Platform Capabilities ChromeDriver Extensions Chrome Web Store Chromium Web on Android Origin trials Release notes Productivity DevTools Lighthouse Chrome UX Report Accessibility Modern Web Guidance Workbox Puppeteer Experience AI Performance CSS and UI Identity Payments Privacy and security Resources All documentation Baseline web.dev PageSpeed Insights audit The Privacy Sandbox Isolated Web Apps (IWA) Declarative partial updates X GitHub Mastodon Bluesky Homepage X GitHub Mastodon 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. ... <template for="placeholder"> 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. 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: ... <template for="another-placeholder"> In this case, Loading… shows until the <template> is seen and then is replaced with the new content. ... <template for="results"> <template for="results"> This results in the following HTML after being parsed: With the final processing instruction at the end in case any more <template for="results"> are added to the document later. Photo album demo implemented with out-of-order streaming (source) Both the status and photos are streamed into the HTML after the initial layout. Island architecture. A common pattern popularized by frameworks like Astro the island architecture where components are hydrated independently on top of static HTML. 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. These are just some use cases, and it is exciting to see what developers use this new API for. <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>). Future potential additions Client side includes. For example, <template for="footer" patchsrc="/partials/footer.html">. Polyfill setHTML 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? Few developers could honestly look at those APIs and confidently answer those questions for each of them. Action Set the HTML contents of the element Replace the entire element with this HTML Add the HTML before the element Add the HTML as the first child of the element Add the HTML as the last child of the element Add the HTML after the element 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. contentElement.setHTML(newHTML); The streaming versions work with the Streams API such as with a getWriter(): // Example stream of updating content writer.close(); Or, alternatively from a fetch response, with pipe chains: const response = await fetch('/api/content.html'); response.body We're also planning to add a convenience method where you can stream directly without needing the intermediate TextDecoderStream() step. // Only allows basic formatting contentElement.setHTML(newHTML, {sanitizer: basicFormattingSanitzer}); "Unsafe" methods Action Set the HTML contents of the element Replace the entire element with this HTML Add the HTML before the element Add the HTML as the first child of the element Add the HTML as the last child of the element Add the HTML after the element The "unsafe" insertion and streaming methods These "unsafe" methods switch off the sanitizer by default (you can specify a custom sanitizer if you wish) and also allow scripts to be run with an optional runScripts option (which defaults to false). contentElement.setHTMLUnsafe(newHTML, {runScripts: true}); The "unsafe" wording in the method is to remind developers of the potential risk and how they may want to sanitize or restrict scripts, not to say that these methods shouldn't be used. Dynamic streaming of large content updates in Single Page Apps. As mentioned previously, a big drawback of current SPAs is they couldn't benefit from the streaming nature of initial HTML loads—until now! Again, those are just a couple of examples and we're eager to see what you all come up with! Integration of streaming with the Trusted Types API requires using a new createParserOptions method which allows injecting a sanitizer to any HTML setting operation. See the explainer for more details on trusted types integration Polyfill Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Contribute Related content Follow Terms Privacy Manage cookies English Deutsch Español – América Latina Français Indonesia Italiano Nederlands Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어 |
The web has evolved beyond its original static, document-driven medium, with modern rich web applications serving diverse needs ranging from communication to complex content management. Despite advancements in HTML and CSS, the inherent in-order delivery of content presents performance challenges in a client-server environment, often necessitating verbose JavaScript for DOM manipulation or the use of heavy frameworks to implement asynchronous component delivery. Recognizing this limitation, the Chrome team is developing Declarative Partial Updates to facilitate a less linear delivery of HTML, enabling content to be delivered out-of-order or dynamically inserted using new JavaScript APIs, which can be tested via Chrome flags starting in version 148. This initiative introduces two main sets of APIs aimed at improving web performance by relaxing the rigid document mental model. The first set involves out-of-order streaming, utilizing the new <template> HTML element and processing instruction placeholders. This mechanism allows HTML to be delivered in a non-sequential manner. For instance, processing instructions, which were previously ignored in HTML, are now integrated, allowing content to be referenced later. The <template for> API allows content to be replaced based on these instructions. Furthermore, the API includes <?start> and <?end> range markers to display temporary placeholder content while templates are being processed, demonstrating how non-linear HTML content can be streamed and slotted into the document. These techniques offer potential use cases such as the island architecture, enabling components to hydrate independently of static HTML, content delivery when it is ready, and reordering content, such as in mega menus, to prioritize critical elements for initial page load performance. The second major focus addresses dynamic insertion and streaming through enhanced methods for updating content using JavaScript. Existing methods like setHTML, innerHTML, and insertAdjacentHTML possess subtleties regarding content replacement, sanitization, and script execution that developers often struggle to manage consistently. To address this complexity, Chrome proposes a new suite of Static and Streaming APIs that standardize insertion and streaming operations. These APIs introduce corresponding methods for setting, replacing, adding content before, after, or as a child of an element, along with streaming equivalents. For operations, there are explicit Static versions and Streaming versions, depending on whether the content is delivered immediately or through a stream. The API set includes 'Unsafe' versions, such as setHTMLUnsafe and streamHTMLUnsafe, which bypass default sanitization and allow for the execution of scripts via an optional runScripts parameter. This distinction is crucial as it acknowledges the varying levels of trust in the input source, allowing developers to manage the security implications explicitly. The streaming methods interact with the Streams API, enabling performance benefits by avoiding the need to wait for the entire content payload before inserting updates. This allows for dynamic streaming of large content updates in Single Page Applications by delivering content as it becomes available. Combining these capabilities offers significant potential. By streaming <template for> elements alongside dynamic insertion methods, developers can achieve sophisticated content management where dynamic HTML can be slotted into pre-defined processing instruction locations. This combination allows for the dynamic update of different parts of content without needing complex, direct DOM manipulation, thereby reducing boilerplate code and unlocking new performance potentials for the web platform. While considerations remain regarding the integration with the Trusted Types API and potential streaming errors, the overall aim is to make partial updates easier to manage, leading to more efficient and performant web applications. |