3

In Layout XML file, if we don't want to cache a block we use cachable=false. By default, it's going to cache.

When to use cachable=false & how it effects to website performance?

6

Setting a block element cacheable attribute to false can serve several purposes!

  • Used for development purposes if you don't want the block to be cached when you develop the block code
  • Make the element of the page dynamic

For example, the captcha block \Magento\Captcha\Block\Captcha is not cached in Magento 2. It makes sense as it is a dynamic block.

Beware

Something you've got to keep in mind, is that if the cacheable attribute is set to false on a block, it will make the entire page not cacheable which is not ideal in terms of performance.

Obviously, the more uncacheable blocks you have the worse the performance will be.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.