-
Notifications
You must be signed in to change notification settings - Fork 215
Prefetch cart and checkout block assets when cart has contents #5553
Conversation
|
Size Change: 0 B Total Size: 864 kB ℹ️ View Unchanged
|
alexflorisca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice., hopefully this will speed up the checkout process a fair bit! Would be interested to see by how much and if we can measure it somehow. I'll have a think.
The code looks good, again with the caveat that I'm not great at PHP. Wonder how long I can get away with that for haha
When I tried running it in the browser, it looks like the cart isn't loading properly. I can see the fetch to the cart store (wc/store/v1/cart?_locale=user) fails with a 404. That's even when the resources are loaded normally, not from prefetch cache, so I'm not sure why...
f92502a to
cb8fa84
Compare
alexflorisca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for fixing the 404, looks good :)
This PR implements resource hinting for cart and checkout scripts when we can predict the customer will be visiting those pages during the current session. It essentially pre-caches block assets in the background when the page is idle so that when the customer lands on the cart and checkout pages, the block scripts can be loaded from cache.
Fixes #2207
cc @senadir
See:
The new rules include:
Case 3 uses the
prerenderattribute which is not supported in all browsers, but is by Chrome. It does not actually render the page or run JS, but it does pre-load all assets and resources on the page. See https://developers.google.com/web/updates/2018/07/nostate-prefetchTesting
Manual Testing
How to test the changes in this Pull Request:
rel='prefetch'rules. Cart and checkout will not be there.rel='prefetch'rules:If you open network tools at this point and then visit the cart page, you should see the majority of scripts are loaded from cache.
User Facing Testing
Users cannot see these changes in an obvious way, so smoke testing should be performed only of the checkout flow.
Performance Impact
For first time visitors to the cart and checkout pages, this should increase the page loading times due to assets being retrieved from cache rather than the server.
Changelog