Skip to content

perf: add Service Worker for PWA offline support + CIA stale-while-revalidate caching#2058

Merged
pethers merged 4 commits intomainfrom
copilot/add-service-worker-for-pwa
Apr 27, 2026
Merged

perf: add Service Worker for PWA offline support + CIA stale-while-revalidate caching#2058
pethers merged 4 commits intomainfrom
copilot/add-service-worker-for-pwa

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

  • Service Worker (public/sw.js) with SWR for CIA data + cache-first for HTML/CSS
  • SW registration in src/browser/main.ts
  • tests/service-worker.test.ts (10 specs, all passing)
  • Cypress assertion in cypress/e2e/homepage.cy.js
  • ESLint serviceworker env block
  • FUTURE_ARCHITECTURE.md PWA section updated
  • Review fix: cacheFirst now opens the named cache and reads only from it (was using caches.match which searches all caches, undermining cache versioning); added regression test verifying isolation between riksdagsmonitor-v1 and cia-data-v1

@github-actions github-actions Bot added the size-xs Extra small change (< 10 lines) label Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🏷️ Automatic Labeling Summary

This PR has been automatically labeled based on the files changed and PR metadata.

Applied Labels: size-xs

Label Categories

  • 🗳️ Content: news, dashboard, visualization, intelligence
  • 💻 Technology: html-css, javascript, workflow, security
  • 📊 Data: cia-data, riksdag-data, data-pipeline, schema
  • 🌍 I18n: i18n, translation, rtl
  • 🔒 ISMS: isms, iso-27001, nist-csf, cis-controls
  • 🏗️ Infrastructure: ci-cd, deployment, performance, monitoring
  • 🔄 Quality: testing, accessibility, documentation, refactor
  • 🤖 AI: agent, skill, agentic-workflow

For more information, see .github/labeler.yml.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions github-actions Bot added documentation Documentation updates javascript JavaScript code changes testing Test coverage size-l Large change (250-1000 lines) labels Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copilot AI changed the title [WIP] Add service worker for PWA offline support and caching perf: add Service Worker for PWA offline support + CIA stale-while-revalidate caching Apr 27, 2026
Copilot AI requested a review from pethers April 27, 2026 13:27
@pethers pethers marked this pull request as ready for review April 27, 2026 13:35
Copilot AI review requested due to automatic review settings April 27, 2026 13:35
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class PWA offline support by introducing a repository-managed service worker and wiring it into the browser entrypoint, with targeted caching for CIA datasets and basic shell assets.

Changes:

  • Added a Workbox-free service worker (public/sw.js) with separate caches for static shell assets and CIA data (SWR).
  • Registered the service worker from src/browser/main.ts (deferred to window.load) and updated ESLint globals for the SW context.
  • Added unit tests for the service worker behavior (VM sandbox) and a Cypress assertion for Service Worker API availability.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/service-worker.test.ts Adds Vitest coverage for install/activate/fetch handlers and caching helpers using a VM sandbox + fake CacheStorage.
src/browser/main.ts Registers /sw.js on load to enable PWA/offline behavior.
public/sw.js Implements caching strategies (SWR for CIA data, cache-first for documents/styles, passthrough for other requests).
eslint.config.js Adds serviceworker globals for public/sw.js to avoid no-undef on SW globals.
cypress/e2e/homepage.cy.js Adds an E2E assertion that navigator.serviceWorker is present.
FUTURE_ARCHITECTURE.md Documents the implemented service worker approach and cache names.

Comment thread public/sw.js Outdated
Comment on lines +124 to +129
const cached = await caches.match(request);
if (cached) return cached;

const response = await fetch(request);
if (response && response.ok) {
const cache = await caches.open(cacheName);
@pethers
Copy link
Copy Markdown
Member

pethers commented Apr 27, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 27, 2026

@copilot apply changes based on the comments in this thread

Fixed in 73ff3f0: cacheFirst now opens the named cache and reads only from it (cache.match(request) instead of caches.match(request)), preserving the version isolation between riksdagsmonitor-v1 and cia-data-v1. Added a regression test that plants a response in the wrong cache and asserts cacheFirst misses + falls through to the network.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@pethers pethers merged commit cdd4ff9 into main Apr 27, 2026
25 checks passed
@pethers pethers deleted the copilot/add-service-worker-for-pwa branch April 27, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation updates javascript JavaScript code changes size-l Large change (250-1000 lines) size-xs Extra small change (< 10 lines) testing Test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Implement Service Worker for PWA offline support and CIA data stale-while-revalidate caching

3 participants