Prefer-No-Speculative-Parsing

Unofficial Proposal Draft,

More details about this document
This version:
https://explainers-by-googlers.github.io/prefer-no-speculative-parsing
Issue Tracking:
GitHub
Editor:
(Google LLC)

Abstract

The Prefer-No-Speculative-Parsing HTTP response header allows a developer to request the user agent to not use the default speculative behavior.

Status of this document

1. Introduction

A document can request the user agent that the default speculative parsing behavior is not used, by using the Prefer-No-Speculative-Parsing HTTP header. This header is a HTTP structured field whose value must be Boolean.

The consequence of using this header is that the resulting Document’s active speculative HTML parser might be set to null. This header indicates only a preference from the Document on how the speculative HTML parser may behave, which the user agent can choose to ignore. In terms of observable effects, this means that any fetches originating from speculative HTML parser may be avoided and any time spent in speculative parsing may be reduced. Resources that were being fetched as part of a speculative fetch, will then be fetched as part of the normal document parsing. Behind the scenes, this preference can allow user agents to skip the time spent in speculative parsing, and deallocate any implementation specific resources corresponding to speculative parsing for additional efficiency.

2. Modifications to HTML’s Speculative HTML parsing

  1. Modify HTML § 13.2.8 Speculative HTML parsing to add the following line:

    • Each Document has a prefer no speculative HTML parsing boolean. It is initially false.

  2. Rewrite step 1 of start the speculative HTML parser to:

    1. Optionally, return. The user agent may especially wish to return if parser’s Document's prefer no speculative HTML parsing is true, as that indicates the Document prefers to opt out of speculative HTML parsing.

3. Modifications to Document creation

  1. Modify create and initialize a Document object under HTML § 7.5.1 Shared document creation infrastructure section by inserting the following steps between the current step 9 and 10:

    1. Let preferNoSpeculativeHTMLParsingHeader be the result of get a structured field value given Prefer-No-Speculative-Parsing from navigationParams’s response's header list.

    2. Let preferNoSpeculativeHTMLParsing be true if preferNoSpeculativeHTMLParsingHeader is not null and preferNoSpeculativeHTMLParsingHeader[0] is the boolean true; otherwise false.

  2. Modify the current step 10 to set document’s prefer no speculative HTML parsing to preferNoSpeculativeHTMLParsing.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.


Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[DOM]
Anne van Kesteren. DOM Standard. Living Standard. URL: https://dom.spec.whatwg.org/
[FETCH]
Anne van Kesteren. Fetch Standard. Living Standard. URL: https://fetch.spec.whatwg.org/
[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119