diff --git a/src/Service/Rule/PageCache.php b/src/Service/Rule/PageCache.php index 12a2ccc..54f1abc 100644 --- a/src/Service/Rule/PageCache.php +++ b/src/Service/Rule/PageCache.php @@ -92,6 +92,22 @@ public function process(string $body): string ); event.waitUntil(Promise.all(done)); }); +fetchAsync = async (url) => { + await fetch(url); +} +self.addEventListener('message', (event) => { + if (event.data && event.data.type === 'PREFETCH') { + const urls = event.data.payload.urls || []; + const done = urls.map( + path => + pageCacheStrategy.handleAll({ + event, + request: new Request(path), + })[1] + ); + event.waitUntil(Promise.all(done)); + } +}); PAGE_CACHE_RULE_STRATEGY; return $body . PHP_EOL . PHP_EOL . trim($declaration); diff --git a/src/Service/Rule/PrefetchOnDemand.php b/src/Service/Rule/PrefetchOnDemand.php deleted file mode 100644 index 3c55257..0000000 --- a/src/Service/Rule/PrefetchOnDemand.php +++ /dev/null @@ -1,27 +0,0 @@ - { - await fetch(url); -} -self.addEventListener('message', (event) => { - if (event.data && event.data.type === 'PREFETCH') { - const urls = event.data.payload.urls || []; - urls.forEach((url) => fetchAsync(url)); - } -}); -PREFETCH_STRATEGY; - - return $body . PHP_EOL . PHP_EOL . trim($declaration); - } -}