For the complete documentation index, see llms.txt. This page is also available as Markdown.

Complete Example

This page provides comprehensive examples of Service Worker configurations, from basic to advanced scenarios. Use these as starting points for your own PWA implementation.

Quick Start: Minimal Configuration

The simplest configuration that enables basic offline functionality:

/config/packages/pwa.yaml
pwa:
    manifest: "/manifest.json"
    serviceworker: "sw.js"  # Create an empty assets/sw.js file

This gives you:

  • Service worker registration

  • Asset precaching (CSS, JS, images from AssetMapper)

  • Image caching (on-demand)

  • Font caching (on-demand)

  • Page caching with NetworkFirst strategy

  • Automatic cache management

The sw.js file in your /assets/ folder can be empty. The bundle generates all the necessary code automatically.

Intermediate: Custom Cache Settings

Enhanced configuration with customized caching behavior:

Complete configuration showcasing all major features:

E-commerce Application Example

Optimized for online stores with product images and dynamic content:

Content/Blog Application Example

Optimized for content-heavy sites with articles and media:

SaaS/Dashboard Application Example

Optimized for real-time data and user interactions:

Testing Your Configuration

After implementing your service worker configuration, test it thoroughly:

1. Development Testing

2. Chrome DevTools Inspection

  1. Open DevTools (F12)

  2. Go to Application tab

  3. Check:

    • Service Workers: Should show "activated and is running"

    • Cache Storage: Verify all configured caches exist

    • Network: Set to Offline and test navigation

3. Lighthouse Audit

Run a PWA audit to verify your configuration:

  1. Open DevTools → Lighthouse

  2. Select "Progressive Web App"

  3. Click "Generate report"

  4. Verify:

    • Service worker registered

    • Offline support working

    • Caching configured properly

Common Configuration Patterns

Pattern 1: Aggressive Caching (Maximum Offline Support)

Use when: Offline-first is critical, content updates infrequently

Pattern 2: Fresh Content (Minimum Caching)

Use when: Real-time data is essential, caching is backup only

Use when: Good offline UX + reasonably fresh content

Next Steps

After configuring your service worker:

  1. Test offline functionality: Disconnect network and verify app works

  2. Monitor cache size: Check DevTools → Application → Storage

  3. Add custom logic: Create Custom Service Worker Rules

  4. Implement background sync handlers: Use Symfony UX components

  5. Configure push notifications: Set up notification handling

Last updated

Was this helpful?