Complete Example
pwa:
serviceworker:
enabled: true
dest: /sw.js
scope: /
skip_waiting: true
config:
use_cdn: false
version: '7.3.0'
workbox_public_url: '/workbox'
workbox:
# Asset caching (CSS, JS from Asset Mapper)
asset_cache:
enabled: true
regex: '/\.(css|js|woff2?)$/'
cache_name: 'assets-cache'
max_entries: 100
max_age: 31536000 # 1 year
# Image caching
image_cache:
enabled: true
regex: '/\.(png|jpg|jpeg|gif|svg|webp|avif)$/'
cache_name: 'images-cache'
max_entries: 60
max_age: 2592000 # 30 days
# Font caching
font_cache:
enabled: true
regex: '/\.(woff|woff2|ttf|otf|eot)$/'
cache_name: 'fonts-cache'
max_entries: 30
max_age: 31536000 # 1 year
# Google Fonts caching
google_font_cache:
enabled: true
cache_name: 'google-fonts'
max_entries: 20
max_age: 31536000
# Resource caching (pages, API)
resource_caches:
- match_callback: 'navigate'
cache_name: 'pages-cache'
strategy: 'StaleWhileRevalidate'
broadcast: true
max_entries: 50
max_age: 86400 # 1 day
- match_callback: 'regex: /\/api\//'
cache_name: 'api-cache'
strategy: 'NetworkFirst'
network_timeout: 3
max_entries: 100
max_age: 3600 # 1 hour
cacheable_response_statuses: [0, 200]
# Offline fallback
offline_fallback:
page: '/offline'
image: '/images/offline.svg'
font: '/fonts/fallback.woff2'
# Background sync
background_sync:
- queue_name: 'contact-form'
match_callback: 'regex: /\/contact/'
method: 'POST'
max_retention_time: 2880 # 2 days in minutes
broadcast_channel: 'form-sync'
# Cache cleaning on install
clear_cache: true
# Navigation preload
navigation_preload: trueWhat This Configuration Does
Asset, Image, and Font Caching
Page and API Caching
Offline Support
Performance
Combining with Push Notifications
Combining with Periodic Sync
Related Documentation
Last updated
Was this helpful?