-
Notifications
You must be signed in to change notification settings - Fork 219
Performance: Mini Cart block adds an additional ~40 requests on pages it is present. #7176
Comments
This issue has been marked as |
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? |
I think we need to at least have an assessment that finds out:
With this being a big jump in the number of requests, I think it needs investigated. |
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:
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 |
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. |
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) 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,
For me, I can't see any script related to filters. 🤔 Could you share exactly what file name or path that filter has? |
Completely agree. 💯
Done. 👍 |
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. |
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):
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?
The text was updated successfully, but these errors were encountered: