Refreshing the Mini Cart and Other Customer Sections in Magento 2

Refreshing the Mini Cart and Other Customer Sections in Magento 2

Magento 2 caches customer-specific blocks like the mini cart in the browser’s local storage. After a custom AJAX action, you may need to refresh them so the page shows current data.

The script

List the sections you want to reload in the array:

        require([
           'Magento_Customer/js/customer-data'
        ], function (customerData) {
            var sections = ['cart','checkout-data'];
            customerData.invalidate(sections);
            customerData.reload(sections, true);
        });

For server-side actions, you can also declare the sections to invalidate in your module’s sections.xml, so Magento refreshes them automatically.

Stuck on something similar? Our Magento development team is happy to take a look.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.