From 3713ae113e2c01b6b4908f614aad0c441b241615 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Sun, 31 Mar 2024 18:58:36 +0200 Subject: [PATCH 1/2] Remove ImportMapConfigReader dependency from PwaRuntime (#152) * Remove ImportMapConfigReader dependency from PwaRuntime The dependency on ImportMapConfigReader has been removed from PwaRuntime code to simplify Workbox URL generation. The URL is now directly derived from the `workboxPublicUrl` property of the serviceWorker's workbox object. This makes the code more maintainable and easy to read. * Remove ImportMapConfigReader dependency from PwaRuntime The ImportMapConfigReader dependency was removed from PwaRuntime.php, thus simplifying the Workbox URL generation process. The URL is now directly derived, resulting in a cleaner, more readable and easily maintainable codebase. --- src/Twig/PwaRuntime.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Twig/PwaRuntime.php b/src/Twig/PwaRuntime.php index dc9d4de..e55388c 100644 --- a/src/Twig/PwaRuntime.php +++ b/src/Twig/PwaRuntime.php @@ -8,7 +8,6 @@ use SpomkyLabs\PwaBundle\Dto\Icon; use SpomkyLabs\PwaBundle\Dto\Manifest; use Symfony\Component\AssetMapper\AssetMapperInterface; -use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader; use Symfony\Component\AssetMapper\MappedAsset; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Mime\MimeTypes; @@ -25,8 +24,6 @@ public function __construct( private bool $manifestEnabled, #[Autowire('%spomky_labs_pwa.sw.enabled%')] private bool $serviceWorkerEnabled, - #[Autowire('@asset_mapper.importmap.config_reader')] - private ImportMapConfigReader $importMapConfigReader, private AssetMapperInterface $assetMapper, private Manifest $manifest, #[Autowire('%spomky_labs_pwa.manifest.public_url%')] @@ -94,8 +91,7 @@ private function injectServiceWorker(string $output, bool $injectSW, array $swAt $registerOptions = sprintf(', {%s}', mb_substr($registerOptions, 2)); } if ($serviceWorker->workbox->enabled === true) { - $hasWorkboxWindow = $this->importMapConfigReader->findRootImportMapEntry('workbox-window') !== null; - $workboxUrl = $hasWorkboxWindow ? 'workbox-window' : 'https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-window.prod.mjs'; + $workboxUrl = sprintf('%s%s', $serviceWorker->workbox->workboxPublicUrl, '/workbox-window.prod.mjs'); $declaration = << import {Workbox} from '{$workboxUrl}'; From bf6b4cf8a699527820965385323ab7cd7caace8c Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 4 Apr 2024 21:24:46 +0200 Subject: [PATCH 2/2] Swap maxEntries and maxAgeInSeconds arguments (#157) The arguments maxEntries and maxAgeInSeconds in the ExpirationPlugin::create() function have been swapped. This change fixes the data misalignment which was causing issues with data retention in the GoogleFontCache. --- src/CachingStrategy/GoogleFontCache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CachingStrategy/GoogleFontCache.php b/src/CachingStrategy/GoogleFontCache.php index 94cf243..7369dd4 100644 --- a/src/CachingStrategy/GoogleFontCache.php +++ b/src/CachingStrategy/GoogleFontCache.php @@ -44,8 +44,8 @@ public function getCacheStrategies(): array ->withPlugin( CacheableResponsePlugin::create(), ExpirationPlugin::create( - $this->workbox->googleFontCache->maxAgeInSeconds() ?? 60 * 60 * 24 * 365, - $this->workbox->googleFontCache->maxEntries ?? 30 + $this->workbox->googleFontCache->maxEntries ?? 30, + $this->workbox->googleFontCache->maxAgeInSeconds() ?? 60 * 60 * 24 * 365 ), ), ];