File page-cache.js not loaded in head
-
15-03-2021 - |
Question
I have some problems with form_key when default FULL PAGE CACHE enabled. And i found out that page-cache.js doesn't load in head section. And there is no "X-Cache:" headers. I've tried everything..
Why can it be? And how it should loading?
Solved! Solution is here - https://magento.stackexchange.com/a/291924/83140
La solution
Answering your question: the most common cause why FPC is not working is persistence of some block which is not cacheable (in layout block has cacheable="false").
You are expecting the wrong indicator. Let's have a look at how FPC works:
<type name="Magento\Framework\App\FrontControllerInterface">
<plugin name="front-controller-builtin-cache" type="Magento\PageCache\Model\App\FrontController\BuiltinPlugin"/>
<plugin name="front-controller-varnish-cache" type="Magento\PageCache\Model\App\FrontController\VarnishPlugin"/>
</type>
Here are two ways: if we use native FPC or Varnish. No FrontController native workflow if the page is cached.
Native FPC
public function aroundDispatch(FrontControllerInterface $subject, \Closure $proceed, RequestInterface $request)
{
$this->version->process();
if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
return $proceed($request);
}
$result = $this->kernel->load();
if ($result === false) {
$result = $proceed($request);
if ($result instanceof ResponseHttp) {
$this->addDebugHeaders($result);
$this->kernel->process($result);
}
} else {
$this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true);
}
return $result;
}
Let's have a look at process()
/**
* Handle private content version cookie set cookie if it is not set.
* Increment version on post requests. In all other cases do nothing.
*
* @return void
*/
public function process()
{
if ($this->request->isPost()) {
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
->setDuration(self::COOKIE_PERIOD)
->setPath('/')
->setSecure($this->request->isSecure())
->setHttpOnly(false);
$this->cookieManager->setPublicCookie(self::COOKIE_NAME, $this->generateValue(), $publicCookieMetadata);
}
}
Original comment tells everything. When post request we set a cookie with the name private_content_version
Try to load content from cache and if it exists - loads it and set a header with the name X-Magento-Cache-Debug
(In developer mode only)
Varnish instead of FPC
public function afterDispatch(FrontControllerInterface $subject, $result)
{
if ($this->config->getType() == Config::VARNISH && $this->config->isEnabled()
&& $result instanceof ResponseHttp
) {
$this->version->process();
if ($this->state->getMode() == AppState::MODE_DEVELOPER) {
$result->setHeader('X-Magento-Debug', 1);
}
}
return $result;
}
Same process()
method and header 'X-Magento-Debug'.
Autres conseils
Solved. The problem was in custom Magento_Theme default.xml layout. There was
<referenceContainer name="main">
<container name="content.top" label="Main Content Top"/>
<container name="content" label="Main Content Area"/>
<container name="content.aside" label="Main Content Aside"/>
<container name="content.bottom" label="Main Content Bottom"/>
</referenceContainer>
It's the same as in Magento module-theme default.xml . As i can understand - it was wrong redeclaring of containers. Correct me if I'm wrong.