magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.4k stars 9.29k forks source link

Registers an unload listener #38376

Open dandrikop opened 6 months ago

dandrikop commented 6 months ago

Description

Magento registers an unload listener for home, product and category pages. As a result the Back / Forward Cache of the visitor's browser is not used. You can easily reproduce it by following the steps below:

  1. Open the Developer Tools of Chrome browser.
  2. Select the "Application" tab on the top.
  3. At the section "Background services" on the left, select the Back/forward cache.
  4. Visit any product page of the store.
  5. Click on the blue button "Test back/forward cache", and you will see the view below:

298844835-a2e32d03-023b-4963-a1b1-4d51bc03ce8d

Expected behavior

Magento should not register an unload listener for home, product and category pages.

Benefits

Use the bfcache of browsers and allow faster navigation.

Additional information

No response

Release note

No response

m2-assistant[bot] commented 6 months ago

Hi @dandrikop. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

dandrikop commented 6 months ago

I have verified the above issue with Magento 2.4.6-p1.

andrewbess commented 6 months ago

Thank you @dandrikop Thank you for your collaboration Let me check it

andrewbess commented 6 months ago

@magento give me 2.4.6 instance

magento-deployment-service[bot] commented 6 months ago

Hi @andrewbess. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 6 months ago

Hi @andrewbess, here is your Magento Instance: https://f2349b08592f91c87159e4067b4e8618.instances-prod.magento-community.engineering Admin access: https://f2349b08592f91c87159e4067b4e8618.instances-prod.magento-community.engineering/admin_1c0d Login: be17cd2c Password: 53128d98b02d

dandrikop commented 6 months ago

Hello @andrewbess

The below article considers Back/Forward Cache as important:

https://web.dev/articles/bfcache

Typically, home, product and category pages are preferred to be cached by Back/Forward Cache, while shopping cart view and checkout pages should not. However, it is recommended that the administrator is allowed to configure which page types to be cached by Back/Forward Cache, as some store owners may have different needs.

dooblem commented 4 months ago

If you are using Varnish or Fastly (which is recommended), the cache-control: no-store flag is also always added on html pages, causing the bfcache to be disabled as explained in web.dev article .

If using Varnish it's here : https://github.com/magento/magento2/blob/2.4/app/code/Magento/PageCache/etc/varnish6.vcl#L233

If using Fastly (in vcl_deliver): https://github.com/fastly/fastly-magento2/blob/775b5a1f434c3818edc66534dda25a3373971fd1/etc/vcl_snippets/deliver.vcl#L8

Apparently Amasty is selling a module allowing to choose on which pages you want to exclude bfcache...

https://amasty.com/bfcache-for-magento-2.html https://amasty.com/docs/doku.php?id=magento_2:back_forward_cache

gilbertococchi commented 2 months ago

Thanks for creating this issue.

I really believe the biggest issue with BFCache and Magento are not the unload event handlers (that are ignored on Chrome Mobile Android anyway) but the fact that no-store is always used as @dooblem correctly highlighted.

Do you think there would be appetite to change this status quo?

I mean changing the No Cache scenario to use all headers info except "no-store"?