Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from meanbee/10-backend-caching
Browse files Browse the repository at this point in the history
Force network-only for backend requests
  • Loading branch information
tgerulaitis authored Nov 28, 2017
2 parents f228200 + 8223233 commit bf4a32c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
17 changes: 17 additions & 0 deletions src/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions src/view/frontend/templates/serviceworker.js.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?php echo $block->getBackendPathPrefix() ?>', wbsw.strategies.networkOnly());

// Serve paths with configured custom strategies
// #####################################

Expand Down

0 comments on commit bf4a32c

Please sign in to comment.