Use optimistic checkout redirect URL loading strategy to improve checkout load time #2520
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What/Why?
As an optimization for the checkout loading speed, this PR adds an optimistic loading of the checkout redirect URL into the client side state at the time the cart page loads. If the user clicks the "checkout" button quickly (within a few seconds of loading the page), they will be redirected immediately, without the need to wait for roundtrip to generate the checkout redirect URL. In practice, this will save about ~500ms of latency on a desktop/strong connection, and perhaps more on mobile.
As the JWT expires after 30 seconds, client side code will compare the
iat
andeat
against the client side time (with a best-effort attempt to account for skew) in order to decide if the JWT should be considered expired, in which case it will be re-generated and the user will be redirected as they were before this change - slower but reliable for this critically important navigation.The net result is an improvement in load speed for shoppers who click "checkout" quickly, who are probably the most impatient ones anyways. :)
Todo:
Testing
Preview deployment
Migration