Magento 2 Cart Performance: Unpacking the Redundant AJAX Reload with Tax-Inclusive Pricing

Magento 2 Cart Performance: Unpacking the Redundant AJAX Reload with Tax-Inclusive Pricing

As e-commerce migration experts at Shopping Mover, we constantly monitor the Magento ecosystem for insights that can impact store performance and user experience. A recent GitHub issue (Issue #41100) highlights a subtle yet significant bug affecting Magento Open Source 2.4.9 and `2.4-develop` branches, specifically concerning the cart page's behavior when displaying prices including tax.

The Redundant Cart Reload Explained

The core of the issue lies in an unnecessary AJAX request fired on the cart page. When a Magento store is configured to display prices and subtotals 'Including Tax' (tax/cart_display/price = 2 and tax/cart_display/subtotal = 2), users experience a redundant full-page cart HTML reload. After the initial page load and Knockout cart totals render, the browser issues an additional GET /checkout/cart/?ajax=1&_=timestamp request. While seemingly minor, this extra network call can contribute to a slightly slower perceived page load and an less optimal user experience.

Diving into the Root Cause

The author, khoimm92, meticulously traced the problem to the Magento_Checkout/js/cart/ensure-subtotal-sync.js script, which is wired from cart/form.phtml and used by themes like Luma. The script's function getCentralSubtotal() attempts to calculate the sum of cart item subtotals by specifically looking for elements with the selector:

'#shopping-cart-table .col.subtotal .price-excluding-tax .cart-price'

Here's the critical flaw: when Magento is configured to display prices including tax, the row price template renders .price-including-tax .cart-price elements and does not render the .price-excluding-tax elements. Consequently, getCentralSubtotal() returns 0. This zero value then mismatches the actual non-zero summary subtotal displayed on the page, leading the trySync() function to erroneously believe the cart is out of sync. This triggers the redundant AJAX call to reload the cart HTML.

The issue was confirmed locally by the author, observing that with tax/cart_display/subtotal = 2, the excl-tax nodes are indeed empty, while incl-tax nodes correctly match the summary, yet the AJAX reload still occurs.

Proposed Solution and Community Response

The suggested fix involves modifying the getCentralSubtotal() logic within app/code/Magento/Checkout/view/frontend/web/js/cart/ensure-subtotal-sync.js. The proposal is to make the script more robust by prioritizing `.price-excluding-tax` when present (e.g., in 'both-prices' display mode), but falling back to `.price-including-tax` or even a bare `.cart-price` if the excl-tax elements are not rendered.

The Magento Community Engineering team, specifically `engcom-Bravo`, has successfully reproduced and confirmed the issue on a latest 2.4-develop instance, validating the initial report. This confirmation is a crucial step towards an official fix being implemented in future Magento releases.

Impact for Merchants and Developers

For merchants, this bug, while not critical (S3 severity), represents a minor performance overhead and a slight degradation in user experience. For developers, understanding this root cause is invaluable. It provides a clear path for implementing a temporary workaround if immediate optimization is required or for contributing to the official fix. This insight underscores the importance of granular frontend JavaScript logic in overall store performance, especially in complex areas like the checkout process where every millisecond counts.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools