Conversation
This allows the use of the bfcache
This makes sure any JS code gets reseted to the default state for a improved UX
This makes sure any JS code gets reseted to the default state for a improved UX
This checks for a invalid state and forces a reload. While this could be done beter the core logic does not allow this, so instead we use the current logic and use a simple refresh to update the page state, simple but 100% efficient.
|
Hi @GrimLink. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
|
@magento run all tests |
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
|
@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE |
|
@magento run all tests |
|
@magento run all tests |
This pull request makes Magento 2 storefront pages eligible for the browser Back/Forward Cache (BFCache). BFCache is one of the highest-impact performance optimisations available in modern browsers. When eligible, navigating back or forward restores a frozen snapshot of the page instantly, eliminating the network round-trip and re-render entirely. Google's Chrome data shows BFCache restores are on average 10x faster than a normal navigation. It improves Core Web Vitals scores (LCP, INP) and directly benefits conversion rates on pages users return to, such as product listings, PDPs, and the cart. Magento 2 is currently ineligible on all storefront pages due to two blockers: the
Cache-Control: no-storeresponse header and several JS components that leave interactive elements in a broken state on restore. This pull request removes both.Description (*)
1.
Cache-Control: no-storeresponse headerPHP and Varnish VCL configurations set
Cache-Control: no-storeon all non-static frontend responses. Browsers treatno-storeas an explicit opt-out from BFCache regardless of other headers. The fix replacesno-store, no-cache, must-revalidate, max-age=0withno-cache, must-revalidate, max-age=0inFramework\App\Response\Http::setNoCacheHeaders(),Magento_Cms404 controller, and all four Varnish VCL versions (4, 5, 6, 7). The Varnishvcl_backend_responseHit-For-Pass conditions are simplified to remove the now-unreachableno-storechecks and the deadSurrogate-Controlcondition (Magento never sets that header from PHP).2. Stale JavaScript state on BFCache restore
When a page is restored from BFCache the browser fires a
pageshowevent withpersisted: true. Without explicit handling, interactive UI state is frozen at the moment of navigation. Apageshowhandler is added to each affected component:lib/web/mage/menu.js— collapses open submenus and clears mobile nav open stateMagento_Checkout/js/view/minicart.js— closes the minicart dropdown and resets theaddToCartCallsloading counterMagento_Checkout/js/sidebar.js— re-enables the checkout button (disabled on click to prevent double-submit)Magento_Customer/js/customer-data.js— re-runs the section staleness check (init()) so the cart counter, customer name, and other section-driven UI reflect changes made on other pages while this page was cached. Also reloads the page if the PHP-rendered login state does not match localStorage, which happens when the user logs in or out on another page while this one is cached.Magento_Customer/js/customer-global-session-loader.js— re-runs the missing-firstname check on restoreMagento_Theme/js/view/messages.js— clears cookie and customerData flash messagesMagento_Catalog/js/catalog-add-to-cart.js— resets button text and removes the disabled classMagento_Checkout/js/proceed-to-checkout.js— re-enables the proceed-to-checkout buttonMagento_Customer/js/view/authentication-popup.js— resets theisLoadingobservableMagento_Newsletter/js/newsletter-sign-up.js— re-enables the submit buttonMagento_Review/js/submit-review.js— re-enables the submit buttonMagento_Customer/js/addressValidation.js— re-enables the save address buttonMagento_Multishipping/js/overview.js— hides the loading indicator and restores the Place Order buttonadminhtml/Magento/backend/web/js/theme.js— recalculates menu scroll position, closes any open admin nav submenu and overlay, clears the search field active state, and hides stale loading popupsRelated Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Cache-Controlresponse header. Verify it containsno-cache, must-revalidate, max-age=0and does not containno-store.Questions or comments
BFCache compatibility has already been implemented as third-party modules by two major ecosystem projects. Mage-OS includes it in https://github.com/mage-os/module-theme-optimization and Hyvä includes it in https://github.com/hyva-themes/magento2-theme-module.
Integrating these changes natively into Magento 2 core removes the need for those workarounds and makes all storefronts benefit by default.
Contribution checklist (*)