✅
PWA Bundle
1.2.x
1.2.x
  • PHPWA Bundle
  • How To Create A PWA?
  • How To Install/Remove A PWA?
  • Bundle Installation
  • Development
  • Events
  • Deployment
  • Debugging
  • The Manifest
    • Application Information
      • Scope
      • ID
      • Direction and Language
      • Orientation
      • Description
      • IARC Rating ID
      • Categories
    • Icons
    • Screenshots
    • Shortcuts
    • Protocol Handlers
    • File Handlers
    • Share Target
    • Complete Example
  • The Service Worker
    • Configuration
    • Content Security Policy
    • Custom Service Worker Rule
    • Custom Cache Strategies
    • Workbox
      • Site Manifest Cache
      • Asset Caching
      • Resource Caching
      • Image Caching
      • Font Caching
      • Offline Fallbacks
      • BackgoundSync
      • CDN and Versions
      • Cache Cleaning
      • Custom Cache Strategy
    • Push Notifications
    • Complete Example
  • Favicons
    • Create Favicons
  • Symfony UX
    • Connection Status
    • Prefetch on demand
    • Sync Broadcast
    • BackgroundSync Form
  • Image Management
    • Icons
    • Screenshots
  • Experimental Features
    • Non-Standard Parameters
      • Launch Handler
      • Display Override
      • Related Applications
      • EDGE Side Panel
    • Translations
    • Widgets (Win10+)
Powered by GitBook
On this page
  1. The Service Worker

Custom Cache Strategies

The bundle provides a large set of cache strategies. However, you can define your own strategies if you need a specific behavior that is not already supported.

With a service that implement SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategiesInterface you will be able to return cache strategy objects.

The method process shall return valid JS as a string. This script will be executed by browsers.

src/MyCustomStrategies.php
<?php

declare(strict_types=1);

namespace Acme;

use SpomkyLabs\PwaBundle\CachingStrategy\CacheStrategyInterface;
use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategiesInterface;

final readonly class MyCustomStrategies implements HasCacheStrategiesInterface
{
    /**
     * @return array<CacheStrategyInterface>
     */
    public function getCacheStrategies(): array
    {
        return [
            ... // You cache strategies here
        ];
    }
}

If the service autoconfiguration is enable, the tag will be added automatically. Otherwise, you need to add the tag spomky_labs_pwa.cache_strategy.

Cache Strategies are objects that implement CacheStrategyInterface. The most important function is the rendered JS that will be injected to the Service Worker.

PreviousCustom Service Worker RuleNextWorkbox

Last updated 1 year ago