Magento 2: Block/Remove customer/section/load compare products ajax call

Magento 2: Block/Remove customer/section/load compare products ajax call

September 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2: Block/Remove customer/section/load compare products ajax call

Stopping Unwanted AJAX Calls in Magento 2

You’ve taken the right step by removing the catalog.compare.sidebar and catalog.compare.link blocks from your default.xml layout file to disable compare products functionality. However, you’re still seeing unwanted AJAX calls being triggered across your website.

The issue lies in a different area of the Magento core - specifically, the customer/section/load AJAX call that is responsible for loading sections like the cart and compare products dynamically on pages like the product view or category list page.

Understanding the Customer Section Load AJAX Call

Magento 2 uses JavaScript to load certain sections asynchronously instead of reloading the entire page. This improves performance but can be problematic when you want to completely disable a feature like comparing products.

The customer/section/load call is triggered by default, even if you’ve removed the compare product blocks from your layout. It’s part of the core customer functionality that loads the cart item count and other customer-specific information.

How to Block the Customer Section Load AJAX Call

To completely block this AJAX call, we need to override or extend the Magento JavaScript files responsible for triggering it. We’ll use a theme-specific override of the requirejs-config.js file located in your theme directory.

  1. Navigate to your theme directory:
app/design/frontend/[Vendor]/[Theme]
  1. Create a new requirejs-config.js file if it doesn’t exist already. This is where we’ll add our customizations.

  2. Open the existing or new requirejs-config.js file and add the following code to map the core Magento_Customer/js/customer-data.js file with your own JavaScript file:

var config = {
    config: {
        mixins: {
            'Magento_Customer/js/customer-data': {
                'Vendor_Extension/js/override-customer-data.js': true
            }
        }
    }
};

Replace 'Vendor_Extension' with the actual namespace of your extension.

  1. Create a new JavaScript file named override-customer-data.js in the following directory:
app/design/frontend/[Vendor]/[Theme]/js
  1. Open this new JS file and add the following code to override the default behavior:
define([
    'jquery',
    'Magento_Customer/js/customer-data'
], function ($, customerData) {

    $.widget('mage.customerData', customerData, {
        _loadSection: function (sectionId) {
            if (sectionId === 'compare-products') {
                return;
            }
            return this._super();
        }
    });

    return $.mage.customerData;
});

This code extends the mage.customerData widget and overrides the _loadSection method. If the section ID is ‘compare-products’, it simply returns without triggering the AJAX call, effectively blocking it.

  1. After adding these changes, clear your Magento cache:
bin/magento cache:clean
  1. Verify that the unwanted customer/section/load AJAX calls have stopped being triggered in your browser’s developer tools (Network tab).

Conclusion

Disabling core Magento functionality like compare products requires more than just removing layout blocks - you need to override or extend the JavaScript files responsible for triggering the dynamic content.

By following this guide, you’ve successfully stopped the unwanted customer/section/load AJAX calls from being triggered when comparing products is disabled in your theme. Remember that theme-specific overrides are a powerful tool for customizing Magento’s behavior without affecting core files.

For more advanced customizations and extensions, consider exploring our Laravel Company Extension Development Services to create robust, secure, and scalable solutions tailored to your business needs.

Magento 2 Checkout Catalog Performance

Our network