Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Speculation Rules HTTP Status code support #35624

Merged

Conversation

tunetheweb
Copy link
Contributor

@tunetheweb tunetheweb commented Aug 28, 2024

Description

MDN previously incorrectly stated that status codes 200 and 304 were supported for Speculation Rules based on incorrect data in the Chrome documentation (that has since been corrected).

Motivation

We've had a developer report of confusion due to incorrect information:
WICG/nav-speculation#330

Additional details

See above links.

Details in spec

Related issues and pull requests

@tunetheweb tunetheweb requested a review from a team as a code owner August 28, 2024 16:18
@tunetheweb tunetheweb requested review from wbamberg and removed request for a team August 28, 2024 16:18
@github-actions github-actions bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Aug 28, 2024
Copy link
Contributor

github-actions bot commented Aug 28, 2024

Preview URLs

(comment last updated: 2024-08-28 16:46:19)

Servers can respond based on this header, for example, to log speculative load requests, return different content, or even prevent speculative loading from happening. If a non-success response code is returned (any HTTP status other than 200 or 304), then the page will not be prefetched/prerendered. This is the easiest way to prevent speculative loading, although it is usually a better approach to allow the prefetch/prerender, and use JavaScript to delay any actions that should only happen when the page is actually viewed.
Servers can respond based on this header, for example, to log speculative load requests, return different content, or even prevent speculative loading from happening. If a non-success response code is returned (any HTTP status other than in the 200-299 range after redirects), then the page will not be prefetched/prerendered. In addition the 204 and 205 status codes also prevent prerendering (but do not prevent prefetch).

Using a non-success code (for example a 504) is the easiest way to prevent speculative loading server-side, although it is usually a better approach to allow the prefetch/prerender, and use JavaScript to delay any actions that should only happen when the page is actually viewed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 504 intentional here? This comment: WICG/nav-speculation#330 (comment) suggests 503, which seems closer in intent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good spot! Fixed.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Approving but leaving open in case you want feedback from the people in WICG/nav-speculation#330.

@tunetheweb
Copy link
Contributor Author

Think we're good cause @jeremyroman (the spec author) LGTMed my similar change on the Chrome Docs.

But he can give an LGTM comment if you prefer to wait for that?

@wbamberg wbamberg merged commit fb0fefc into mdn:main Aug 28, 2024
8 checks passed
@wbamberg
Copy link
Collaborator

But he can give an LGTM comment if you prefer to wait for that?

I'm happy if you are!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants