Skip to content

fix(app): add service worker for cache-first static asset loading#27936

Open
BYK wants to merge 1 commit into
anomalyco:devfrom
BYK:fix/service-worker-font-preload
Open

fix(app): add service worker for cache-first static asset loading#27936
BYK wants to merge 1 commit into
anomalyco:devfrom
BYK:fix/service-worker-font-preload

Conversation

@BYK
Copy link
Copy Markdown
Contributor

@BYK BYK commented May 16, 2026

Issue for this PR

Closes #27933, closes #19119, closes #19174

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds three front-end performance optimizations:

Service Worker (public/sw.js):

  • Navigation (HTML): stale-while-revalidate — serves cached index.html instantly while refreshing in the background
  • Hashed assets: cache-first — Vite content-hashed filenames are immutable, so serve from cache indefinitely
  • Other static files (fonts, icons): stale-while-revalidate
  • API and event paths are explicitly excluded from caching

Registration added to entry.tsx — non-blocking, fire-and-forget.

Font preload (index.html):

  • Adds <link rel="preload"> for JetBrainsMono woff2 to start download during HTML parse instead of waiting for CSS evaluation.

font-display: swap (index.css):

  • Adds font-display: swap to the @font-face declaration to prevent invisible text (FOIT) during font download.

How did you verify your code works?

Tested locally: verified SW registers and caches assets on first visit, serves from cache on refresh, and updates in the background. Font loads without invisible text flash. Network tab confirms font preload starts during HTML parse.

Screenshots / recordings

N/A — performance improvement.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add a service worker with three caching strategies:
- Navigation (HTML): stale-while-revalidate for instant page loads
- Hashed assets: cache-first (immutable Vite content-hashed filenames)
- Other static files: stale-while-revalidate

Add font preload link for JetBrainsMono to start download during HTML
parse instead of waiting for CSS evaluation.

Add font-display: swap to prevent invisible text during font download.
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found one related PR:

PR #27934: fix(server): add Cache-Control headers to static assets
#27934

This PR is closely related to #27936 as both address static asset caching performance. While #27934 focuses on server-side Cache-Control headers, #27936 adds client-side service worker caching. They may be complementary approaches to the same performance issue (#27933), or there could be overlap in their solutions. You may want to review both PRs to ensure they work together effectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant