Dynamic content in Magento 2 does not automatically mean you must disable the Full Page Cache for the entire page. That is what Private Contentis designed to help avoid.

A block with cacheable=”false” can make the whole page non-cacheable. With Private Content, the page itself remains cacheable, while only certain user-specific sections are loaded separately and rendered dynamically.

Typical examples include the shopping cart, customer name and wishlist.

The principle is simple: Cacheable content comes from the full page cache; personal content is loaded independently.

cacheable=”false” should not be used indiscriminately just because one area of the page is dynamic. Private Content provides a cleaner solution in many cases without sacrificing full page caching for the entire page.

A simple example is a custom customer section. The PHP class provides the personalized data:

The section is then declared in etc/frontend/di.xml registriert:

In Hyvä, customer sections are available through the event private-content-loaded :

The page itself stays in the full page cache. Only the customer section data is supplied separately in the browser and can vary by visitor.

Private Sections vs. cacheable=”false”: What’s the Difference?
Need help implementing this solution, or still looking for a fix to your Magento problem? Get in touch and I will be happy to help with your project.
Tags: