Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Performance: Mini Cart block adds an additional ~40 requests on pages it is present. #7176

Closed
Tracked by #8556
nerrad opened this issue Sep 18, 2022 · 10 comments
Closed
Tracked by #8556
Assignees
Labels
block: mini-cart Issues related to the Mini-Cart block. focus: performance The issue/PR is related to performance.

Comments

@nerrad
Copy link
Contributor

nerrad commented Sep 18, 2022

First reported in this WordPress Support forum thread and I've confirmed in testing. The Mini-Cart block adds an additional ~40 requests to pages that have the block present (not counting what is lazy loaded). This seems unexpected and something that should be investigated to make sure we're not loading assets unnecessarily on initial page load.

To test, I did the following (in a block theme - I used Block Canvas):

  1. Made sure header template does not contain the Mini Cart block.
  2. Load the home page on the frontend (assuming the home page is using the header template). Observe the number of requests.
  3. Edit the header template to add the Mini Cart block.
  4. Reload the home page and observe the number of requests. You'll see an increase of ~40.

This looks like it may be a regression, I don't recall this large of an overhead being present when the mini cart was first released?

@nerrad nerrad added focus: performance The issue/PR is related to performance. block: mini-cart Issues related to the Mini-Cart block. labels Sep 18, 2022
@github-actions
Copy link
Contributor

This issue has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface issues for review. If you are the author of the issue there's no need to comment as it will be looked at.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Nov 19, 2022
@nerrad
Copy link
Contributor Author

nerrad commented Nov 22, 2022

cc @Aljullu or @danielwrobert do you know if anyone has investigated this?

@nerrad nerrad removed the status: stale Stale issues and PRs have had no updates for 60 days. label Nov 22, 2022
@danielwrobert
Copy link
Contributor

cc @Aljullu or @danielwrobert do you know if anyone has investigated this?

@nerrad not that I'm aware of. Looks like it's still in the backlog pipeline, possibly got lost in the shuffle (unless @Aljullu knows something more).

Do we need to flag it as a high-priority item?

@nerrad
Copy link
Contributor Author

nerrad commented Nov 22, 2022

I think we need to at least have an assessment that finds out:

  • why are these extra requests happening just with the block appearing on the page?
  • how difficult of a fix would it be? Are the requests valid or is this a bug?

With this being a big jump in the number of requests, I think it needs investigated.

@Aljullu
Copy link
Contributor

Aljullu commented Nov 23, 2022

Sorry, I missed this issue. If I remember correctly, this has been the behavior since the beginning. The reason is that we preload those scripts after page load so when the shopper interacts with the Mini Cart, they are ready to be executed.

So:

  • they are downloaded after the page is loaded and finished rendering
  • they don't block or slow down page rendering and they shouldn't affect negatively the performance of the page: they are downloaded in the background, but not executed
  • once they have been downloaded once, they will be in the browser cache, so in practice they are only downloaded on the first page the shopper visits

There is a slightly more in-detail explanation of this mechanism in this post: https://developer.woocommerce.com/2021/11/15/how-does-woocommerce-blocks-render-interactive-blocks-in-the-frontend/#how-about-lazy-loading-the-block-and-its-dependencies

@nerrad
Copy link
Contributor Author

nerrad commented Nov 23, 2022

That makes sense, but there still seems to be something a bit wonky. I would assume that this means the number of requests after the mini-cart is triggered to be minimal if things are pre-loaded but I'm still seeing an additional 15 scripts loaded after the mini-cart is triggered. Including some that don't make sense including active filters-related scripts.

@Aljullu
Copy link
Contributor

Aljullu commented Nov 23, 2022

I would assume that this means the number of requests after the mini-cart is triggered to be minimal if things are pre-loaded but I'm still seeing an additional 15 scripts loaded after the mini-cart is triggered.

Right, you mean these ones? (They are the ones which are loaded for me when I open the Mini Cart and there are products in the cart)

imatge

When the cart is empty, there are only three scripts loaded on open. I guess it might make sense to preload them as well.

Sidenote: I do believe there are improvements we can make here, products-table-frontend.js appears duplicated, and cross-sells looks weird if we aren't displaying any cross sell. 😕

Including some that don't make sense including active filters-related scripts.

For me, I can't see any script related to filters. 🤔 Could you share exactly what file name or path that filter has?

@nerrad
Copy link
Contributor Author

nerrad commented Nov 23, 2022

Okay I did some more testing on an updated environment using the following:

  • WooCommerce 7.1.0
  • WordPress 6.1.1
  • WooCommerce Blocks 9.0.0
  • Twenty Twenty Three 1.0 (likely doesn't matter, but for thoroughness).

Loading on the home page of the site with the default front page of TT3.

I get the following with nothing in the cart:
CleanShot 2022-11-23 at 08 16 37@2x

I get the following with items in the cart:
CleanShot 2022-11-23 at 08 18 15@2x

The filter scripts were showing on a different dev site but it may be something related to an older version of WooCore or something there (same with cross-sells, I'm not seeing it now 🤔 ).

Sidenote: I do believe there are improvements we can make here, products-table-frontend.js appears duplicated, and cross-sells looks weird if we aren't displaying any cross sell. 😕

Agreed, we should definitely avoid duplicates where needed.

Would you mind updating the Support forum thread (linked to in the main description) with an update about how the scripts are loaded and why this shouldn't be a significant "performance hit" in most cases (given the non-blocking pre-fetching of scripts on load and browser caching)? Worth noting that this is still way below "industry leaders" such as Amazon when it comes to the number of requests/MB loaded in total.

@Aljullu
Copy link
Contributor

Aljullu commented Nov 23, 2022

Agreed, we should definitely avoid duplicates where needed.

Completely agree. 💯

Would you mind updating the Support forum thread (linked to in the main description) with an update about how the scripts are loaded and why this shouldn't be a significant "performance hit" in most cases (given the non-blocking pre-fetching of scripts on load and browser caching)? Worth noting that this is still way below "industry leaders" such as Amazon when it comes to the number of requests/MB loaded in total.

Done. 👍

@Aljullu
Copy link
Contributor

Aljullu commented Mar 8, 2023

I did an audit of the scripts loaded to render the Mini Cart block and, first of all, I wanted to reiterate what I said in my comment above: even though the block has many dependencies, most of them are very small and are lazy loaded so they don't block page load. In addition to that, we only execute them (in other words, we only render the drawer contents) when we have a clear indication that the user will interact with the Mini Cart: hovering or focusing the button, adding a product to cart, etc. Lastly, most of those dependencies are shared with the Cart and Checkout blocks, so they will be cached across page views.

Having said that, it's true that there were some improvement opportunities. I'm sharing what I have found so far. Heads-up that I looked at this exploration as "improve Mini Cart performance" in general, not as "try to reduce the number of requests". The reason is that I don't think the number of requests can be reduced significantly (besides a couple of instances I mention below); however, I think there are some gains we can do to avoid blocking scripts and being more intentional preloading scripts we know will be requested.

Given all of this, I'm going to close this issue as complete as everything I identified has open PRs (or will have them by the end of this week) or has follow-up issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: mini-cart Issues related to the Mini-Cart block. focus: performance The issue/PR is related to performance.
Projects
None yet
Development

No branches or pull requests

3 participants