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>
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>