diff --git a/src/Block/Js.php b/src/Block/Js.php index a29d354..9b37d9e 100644 --- a/src/Block/Js.php +++ b/src/Block/Js.php @@ -80,6 +80,16 @@ public function getExternalScriptUrls() return array_filter($scripts); } + /** + * Get the path prefix for backend requests. + * + * @return string + */ + public function getBackendPathPrefix() + { + return $this->config->getBackendPathPrefix(); + } + /** * Get the configured paths with custom caching strategies. * diff --git a/src/Helper/Config.php b/src/Helper/Config.php index 0f1b663..61f1260 100644 --- a/src/Helper/Config.php +++ b/src/Helper/Config.php @@ -18,17 +18,22 @@ class Config extends \Magento\Framework\App\Helper\AbstractHelper /** @var \Magento\Cms\Helper\Page $cmsPageHelper */ protected $cmsPageHelper; + /** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */ + protected $deploymentConfig; + /** @var \Magento\Framework\Serialize\Serializer\Json $serializer */ protected $serializer; public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Cms\Helper\Page $cmsPageHelper, + \Magento\Framework\App\DeploymentConfig $deploymentConfig, \Magento\Framework\Serialize\Serializer\Json $serializer ) { parent::__construct($context); $this->cmsPageHelper = $cmsPageHelper; + $this->deploymentConfig = $deploymentConfig; $this->serializer = $serializer; } @@ -58,6 +63,18 @@ public function getOfflinePageUrl() } } + /** + * Get the prefix path for backend requests. + * + * @return string + */ + public function getBackendPathPrefix() + { + return $this->_urlBuilder->getBaseUrl() + . $this->deploymentConfig->get(\Magento\Backend\Setup\ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME) + . "/*"; + } + /** * Get the configured paths with custom caching strategies. * diff --git a/src/view/frontend/templates/serviceworker.js.phtml b/src/view/frontend/templates/serviceworker.js.phtml index 3055c1c..27879ff 100644 --- a/src/view/frontend/templates/serviceworker.js.phtml +++ b/src/view/frontend/templates/serviceworker.js.phtml @@ -38,6 +38,11 @@ wbsw.precache([ wbsw.router.registerRoute(/\.(png|jpeg|jpg|gif)$/, wbsw.strategies.cacheFirst()); wbsw.router.registerRoute(/\.(js|css)$/, wbsw.strategies.cacheFirst()); +// Serve backend requests with network-only strategy +// ##################################### + +wbsw.router.registerRoute('getBackendPathPrefix() ?>', wbsw.strategies.networkOnly()); + // Serve paths with configured custom strategies // #####################################