Magento 2: Cacheable false for specific block not working

by Rakesh   Last Updated September 02, 2016 08:05 AM

I am trying to detect user’s country based on their IP address and ability to change country as well. However with the use of Full Page Cache, country name is not getting display properly. Sometimes it displays random results.

I have tried to add cacheable=false to block XML file. But adding this would slow down entire page. Since this block is added to all pages, entire site getting slow by adding cacheable=false.

Also tried _isScopeprivate = true to my block PHP __construct() function. But this is also not working.

Is there any way to exclude specific block from FPC without hurting site speed?

I have rewrite currency.phtml template for customize my goal,

<referenceContainer name="header.panel">
            <block class="Vendor\Module\Block\Currency" name="currency" template="Vendor_Module::currency.phtml" cacheable="false"/>
</referenceContainer>

when i am keep cacheable=false in above block its working but page load time take so much time. So I want to remove cacheable="false" from above block.

Any suggestion would be appreciated. Thanks.



Answers 1


cacheable=false on a block makes whole page not cacheable. This is how it is designed, so no problem here.

As for your goal - you want to render user-specific content as part of cached page. Such content should not be rendered on server. It should be retrieved from server using customer data JS api (see mini shopping cart), and rendered using JS.

Anton Kril
Anton Kril
September 02, 2016 10:23 AM

Related Questions


How to clear cache on page loading magento 2?

Updated December 20, 2017 07:09 AM

what is the block name for price block?

Updated April 26, 2015 21:04 PM

removing a template from the cache

Updated July 14, 2015 17:04 PM

FPC (lesti) won't holepunch certain area

Updated June 14, 2016 08:03 AM

Hole punch product price block

Updated February 29, 2016 01:04 AM