From 4f69bcf86d834f983596cd9302b5b2e8378401de Mon Sep 17 00:00:00 2001 From: Phat Pham Date: Fri, 13 Nov 2026 09:34:17 +0700 Subject: [PATCH 1/3] perf: inline critical assets and cache the home page - Inline style.css and the pre-paint theme bootstrap into the server-rendered HTML, removing both render-blocking requests on first load - Edge-cache GET / per URL for five minutes via the Cache API, keyed by APP_VERSION so deploys invalidate it; skip the cache in local dev - Reduce home rendering from five sequential D1 reads to two parallel reads and parallelize the dashboard/health queries - Add immutable caching for versioned static assets; bump the service-worker shell cache and stop precaching the now-inlined assets - Remove the startup forced reflow in preview action placement - Deduplicate favicon requests and add a buildErrors contract test Co-Authored-By: Claude Code --- README.md | 4 +- core/render.ts | 14 ++-- core/service.ts | 50 +++++++------ core/test/service.spec.ts | 11 +++ docs/ARCHITECTURE.md | 7 ++ docs/DEPLOYMENT.md | 3 +- docs/RUNBOOK.md | 2 + platforms/cloudflare/src/index.ts | 118 +++++++++++++++++++++++++----- web-static/_headers | 35 +++++++++ web-static/service-worker.js | 6 +- web-static/static/app.js | 9 ++- 11 files changed, 206 insertions(+), 53 deletions(-) create mode 100644 web-static/_headers diff --git a/README.md b/README.md index 7504d9f..5c1dc2f 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ `feedreader` is server-rendered HTML with vanilla JS/CSS — no framework runtime, no client hydration, no bundler payload. That keeps it genuinely tiny and fast, not just "fast for a SPA." +The home page has no render-blocking asset requests: the stylesheet and pre-paint theme bootstrap are inlined into the HTML, and the response is edge-cached per URL for five minutes. Versioned static assets are served with immutable browser caching; see [`web-static/_headers`](web-static/_headers). + Lighthouse against the production deployment (mobile, simulated throttling): ![Lighthouse report](docs/assets/lighthouse-report.png) @@ -343,7 +345,7 @@ Presentation-layer note: - selected density is stored in `localStorage` under `feedreader.uiDensity` - selected theme is stored in `localStorage` under `feedreader.theme`; valid values are `system` (default), `dark`, `light`, `sepia`, `terminal`, `glacier`, and `ember` - `system` resolves to the device's current light/dark preference and follows changes live; existing `dark`/`light` preferences keep working -- an inline pre-paint theme init script applies the stored preference before the stylesheet loads, avoiding a light/dark flash +- an inline pre-paint theme init script applies the stored preference before first paint, avoiding a light/dark flash (the script is read from `web-static/static/theme-init.js` and inlined with the stylesheet) - article preview is off by default and stored in `localStorage` under `feedreader.articlePreviewEnabled` - bookmark controls are off by default and stored in `localStorage` under `feedreader.bookmarksEnabled`; enabling them shows the bookmark controls and Saved filter, and disabling them hides those controls without deleting saved items - source-specific filters render as **real icon-only buttons** diff --git a/core/render.ts b/core/render.ts index 9882c77..ed474ed 100644 --- a/core/render.ts +++ b/core/render.ts @@ -27,6 +27,11 @@ export interface PageData { canonicalUrl: string; socialImageUrl: string; appVersion: string; + /** Injected by the platform layer so first paint doesn't wait on an + * external stylesheet request. Kept as parameters so core/render.ts stays + * independent of the asset pipeline. */ + inlineCss: string; + themeInitScript: string; } export function escapeHtml(value: unknown): string { @@ -187,17 +192,16 @@ export function renderIndexPage(data: PageData): string { - - - - + + +