The Streaming HTML Rewriter is now available in the Fastly Compute JavaScript SDK!

We’re thrilled to announce a major performance and functionality upgrade for everyone building on Fastly Compute with JavaScript: the new HTMLRewritingStream is officially live in the SDK (v3.35.0).

This new feature gives you a powerful, streaming API to inspect and modify HTML responses directly at the network edge, giving you a serious competitive advantage in performance and agility.

Previously, tasks like injecting tracking scripts, adding personalized widgets, or rewriting internal URLs meant either slow, server-side DOM manipulation (which buffers the entire file) or forcing a full origin hit. Now, you can do it all at the edge:

  1. Streaming Architecture: The Rewriter is based on the web standard Streams API (TransformStream). This means the HTML document is processed, modified, and delivered to the client in fragments, avoiding buffering and keeping your TTFB low.

  2. Blazing Fast: Our implementation, powered by the lol-html Rust crate, is designed for speed. We’ve measured it as up to ~20x faster than general-purpose JavaScript DOM manipulation libraries like LinkeDOM for heavy-duty rewriting tasks.

  3. Ergonomic API: You can target elements and manipulate attributes using familiar CSS

Some ideas to get you started:

  • Decouple and Offload: Cache static HTML from your origin and inject dynamic or personalized components (like a user’s name or cart count) at the edge.

  • Front-End Agility: Instantly inject or modify crucial elements like tags, canonical URLs, or third-party scripts for marketing and SEO without a back-end deployment.

  • Migration Made Easy: Rewrite domain names or path prefixes on hundreds of internal links automatically during a site migration.

Ready to Try It?

The HTMLRewritingStream is available now in version 3.35.0 of the @fastly/js-compute SDK.

Documentation is available @fastly/js-compute docs.

Let us know what you start building with this! If you run into any questions or have feature requests for the rewriter, please drop them in the comments below!

3 Likes

As someone who teaches folk who are new to edge computing, I was very excited to try this as it makes for some great demos lol. I’ll be working on more comprehensive resources showing you how to use the HTML Rewriter to enhance your website behavior, but for now here’s a quick intro tutorial I threw together. It runs through the basics of transforming your web page HTML at the edge with a JavaScript Compute app:

Let us know if you try it! :megaphone:

2 Likes