-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Add SPA shell with bootstrap data example #28434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
2f06fe7
eef93cf
a9efdc8
645c983
d038bb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,354 @@ | ||||||
| --- | ||||||
| summary: Use HTMLRewriter to inject bootstrap data into an SPA shell — whether the shell is served from Workers Static Assets or fetched from an external origin. | ||||||
| tags: | ||||||
| - TypeScript | ||||||
| - SPA | ||||||
| pcx_content_type: example | ||||||
| title: SPA shell with bootstrap data | ||||||
| sidebar: | ||||||
| order: 1001 | ||||||
| description: Use HTMLRewriter to inject prefetched bootstrap data into an SPA shell, eliminating client-side data fetching on initial load. Works with Workers Static Assets or an externally hosted SPA. | ||||||
| reviewed: 2026-02-19 | ||||||
| --- | ||||||
|
|
||||||
| import { TypeScriptExample, WranglerConfig } from "~/components"; | ||||||
|
|
||||||
| This example uses a Worker and [HTMLRewriter](/workers/runtime-apis/html-rewriter/) to inject prefetched API data into a single-page application (SPA) shell. The Worker fetches bootstrap data in parallel with the HTML shell and streams the result to the browser, so the SPA has everything it needs before its JavaScript runs. | ||||||
|
|
||||||
| Two variants are shown: | ||||||
|
|
||||||
| 1. **Static Assets** — The SPA is deployed to [Workers Static Assets](/workers/static-assets/) alongside the Worker. | ||||||
|
||||||
| 1. **Static Assets** — The SPA is deployed to [Workers Static Assets](/workers/static-assets/) alongside the Worker. | |
| 1. **Static Assets** — The SPA is deployed using [Workers Static Assets](/workers/static-assets/) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 2. **External origin** — The SPA is hosted outside Cloudflare (for example, on AWS S3, Vercel, Netlify, or your own server) and the Worker sits in front of it as a reverse proxy. | |
| 2. **External origin** — The SPA is hosted outside Cloudflare, and the Worker sits in front of it as a reverse proxy, improving performance |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include links to the framework docs that are here:
https://developers.cloudflare.com/workers/framework-guides/web-apps
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ## Option 1: SPA on Workers Static Assets | |
| ## Option 1: Single Page App (SPA) built entirely on Workers |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Use this variant when your SPA build output is deployed alongside the Worker using [Workers Static Assets](/workers/static-assets/). | |
| Use this variant when your SPA build output is deployed as part of your Worker using [Static Assets](/workers/static-assets/). |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Use this variant when your HTML, CSS, and JavaScript are deployed outside Cloudflare — for example, on AWS S3, Google Cloud Storage, Vercel, Netlify, or your own server. The Worker acts as a reverse proxy: it fetches the SPA shell from the external origin, uses HTMLRewriter to inject bootstrap data, and streams the modified response to the browser. | |
| Use this variant when your HTML, CSS, and JavaScript are deployed outside Cloudflare. The Worker fetches the SPA shell from the external origin, uses HTMLRewriter to inject bootstrap data, and streams the modified response to the browser. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.