Remove message-based prefetch in favor of prefetching on activate:
- Remove PREFETCH_ASSETS message listener from service worker
- Remove prefetchAssets() call and idle callback from pushHelper.js
- Call prefetchAssets() directly in activate event
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove networkFirstWithShellCache - offline shell caching has limited
value for a real-time chat app that requires network connectivity.
The service worker now only caches static assets (JS, CSS, fonts, images).
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add entry.assets array to precache list for fonts and images.
Increases precached assets from 69 to 86.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Vite manifest has CSS files in two places:
- entry.file (main CSS files)
- entry.css (CSS imported by JS modules)
The previous code only read entry.file, missing CSS from entry.css.
This increases precached assets from 57 to 69.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move build script from scripts/build-service-worker.js to
app/javascript/service-worker/build.js to keep all service worker
related code in one place.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Instead of invalidating the entire cache on every deployment (via git hash
in cache name), use a stable cache name and leverage Vite's content hashes
in filenames.
Changes:
- Use fixed cache name 'chatwoot-assets-v1' instead of 'chatwoot-{git-hash}'
- Add cleanupStaleAssets() to remove old assets not in current manifest
- Unchanged files (same content hash) stay cached across deployments
- Only new/changed files are fetched
- Remove unused getCacheVersion() and CACHE_VERSION references
This significantly reduces bandwidth on deployments since most assets
don't change between releases.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Two issues were causing the service worker to not cache assets in production:
1. The prefetch baseUrl was hardcoded to /vite-dev/ which only exists in
development. In production, assets are served from /packs/. Added
ASSET_PATH build-time constant to use the correct path per environment.
2. The service worker was built before assets:precompile, so the Vite
manifest didn't exist yet, resulting in 0 precached assets. Moved
the SW build to after_assets_precompile so it can read the manifest.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Vite's define option replaces identifiers, not string literals.
Changed from '__CACHE_VERSION__' (string) to __CACHE_VERSION__ (identifier)
so Vite can properly inject the values at build time.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove over-engineering from asset caching service worker:
- Remove retry logic, stats tracking, unused message handlers
- Inline helper functions used only once
- Reduce sw-runtime.js from 314 to 170 lines (46% reduction)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Workbox-based service worker to cache JS, CSS, and fonts
- JS/CSS cached for 30 days, fonts for 1 year
- Support for CDN assets via ASSET_CDN_HOST
- Version-based cache invalidation on deployments
- Automatic cache cleanup for old versions
- Build service worker during asset precompilation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>