Magento – How to Disable Cache in Custom Widget

full-page-cachemagento2widget

I am developing one widget in which I want current customer details. But I am not able to get these details on the homepage, catalog page, product page and other CMS pages.

I have found for this issue and it's because of Full Page Cache. I don't want to disable cache for the full page since it's a widget that customer can add it on any page and disable cache will affect website performance.

I just want to know if there is any solution through which I can keep the page cache untouched and get the customer details in my widget.

If there is any solution please let me know.

Best Answer

Becareful, do not use cacheable="false" because all your page will not be cachable by the FPC and so your store front will have performance issues.

As mention, try to use Ajax request and localstorage in order to load you data dynammicaly.

You can also try to use some Varnish ESI tags.

Official doc : http://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching.html

To sum up, follow this guide : http://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/private-content.html

Related Topic