Custom Service Worker Rule
Basic Example
<?php
declare(strict_types=1);
namespace App\ServiceWorkerRule;
use SpomkyLabs\PwaBundle\Dto\ServiceWorker;
use SpomkyLabs\PwaBundle\ServiceWorkerRule\ServiceWorkerRuleInterface;
final readonly class MyCustomRule implements ServiceWorkerRuleInterface
{
public function __construct(
private ServiceWorker $serviceWorker,
) {}
public function process(bool $debug = false): string
{
return <<<JS
// This will be added to the Service Worker
console.log('FOO-BAR from the Service Worker!');
JS;
}
}Manual Service Registration
Advanced Example with Configuration
Rule Execution Order
Rule
Priority
Purpose
Best Practices
Example: Custom Cache Invalidation
Last updated
Was this helpful?