Skip to content

Commit 0e2ec54

Browse files
eeepsJosh-Cenagithub-actions[bot]
authored
Clarify requirements for render-blocking (mdn#39809)
* Clarify requirements for render-blocking Fixes mdn#39663 Also make clear that we are not only blocking on fetching; also on parsing/application. * Update notes * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update index.md --------- Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 01822ef commit 0e2ec54

File tree

8 files changed

+28
-6
lines changed

8 files changed

+28
-6
lines changed

files/en-us/web/api/htmllinkelement/blocking/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ A string. Must be a space-separated list of blocking tokens listed below indicat
1919
- `render`
2020
- : The rendering of content on the screen is blocked.
2121

22+
> [!NOTE]
23+
> Only `link` elements in the document's `<head>` can possibly block rendering. By default, a `link` element with `rel="stylesheet"` in the `<head>` blocks rendering when the browser discovers it during parsing. If such a `link` element is added dynamically via script, you must additionally set `blocking = "render"` for it to block rendering.
24+
2225
## Examples
2326

2427
```html

files/en-us/web/api/htmlscriptelement/blocking/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ A string. Must be a space-separated list of blocking tokens listed below indicat
1919
- `render`
2020
- : The rendering of content on the screen is blocked.
2121

22+
> [!NOTE]
23+
> Only `script` elements in the document's `<head>` can possibly block rendering. Scripts are not render-blocking by default; if a `script` element does not include `type="module"`, `async`, or `defer`, then it blocks _parsing_, not _rendering_. If such a `script` element is added dynamically via script, you must set `blocking = "render"` for it to block rendering.
24+
2225
## Examples
2326

2427
```html

files/en-us/web/api/htmlstyleelement/blocking/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ A string. Must be a space-separated list of blocking tokens listed below indicat
1919
- `render`
2020
- : The rendering of content on the screen is blocked.
2121

22+
> [!NOTE]
23+
> Only `style` elements in the document's `<head>` can possibly block rendering. By default, a `style` element in the `<head>` blocks rendering when the browser discovers it during parsing. If such a `style` element is added dynamically via script, you must additionally set `blocking = "render"` for it to block rendering.
24+
2225
## Examples
2326

2427
```html

files/en-us/web/api/view_transition_api/using/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,17 @@ Before running a cross-document transition, you ideally want to wait until the s
501501
2. Critical scripts are loaded and run.
502502
3. The HTML visible for the user's initial view of the page has been parsed, so it renders consistently.
503503
504-
Styles are render blocked by default, and scripts can be render blocked using the [`blocking="render"`](/en-US/docs/Web/HTML/Reference/Elements/script#blocking) attribute.
504+
Styles are render blocked by default unless they are added to the document dynamically, via script. Both scripts and dynamically-added styles can be render blocked using the [`blocking="render"`](/en-US/docs/Web/HTML/Reference/Elements/script#blocking) attribute.
505505
506506
To ensure that your initial HTML has been parsed and will always render consistently before the transition animation runs, you can use [`<link rel="expect">`](/en-US/docs/Web/HTML/Reference/Attributes/rel#expect). In this element, you include the following attributes:
507507
508508
- `rel="expect"` to indicate that you want to use this `<link>` element to render block some HTML on the page.
509509
- `href="#element-id"` to indicate the ID of the element you want to render block.
510510
- `blocking="render"` to render block the specified HTML.
511511
512+
> [!NOTE]
513+
> In order to block rendering, `script`, `link`, and `style` elements with `blocking="render"` must be in the `head` of the document.
514+
512515
Let's explore what this looks like with an example HTML document:
513516
514517
```html

files/en-us/web/html/reference/attributes/rel/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following table lists some of the most important existing keywords. Every ke
2626
| [`compression-dictionary`](/en-US/docs/Web/HTML/Reference/Attributes/rel/compression-dictionary) | Link to a {{glossary("Compression dictionary transport", "compression dictionary")}} that can be used to compress future downloads for resources on this site. | Link | Not allowed | Not allowed |
2727
| [`dns-prefetch`](/en-US/docs/Web/HTML/Reference/Attributes/rel/dns-prefetch) | Tells the browser to preemptively perform DNS resolution for the target resource's origin. | External Resource | Not allowed | Not allowed |
2828
| [`external`](#external) | The referenced document is not part of the same site as the current document. | Not allowed | Annotation | Annotation |
29-
| [`expect`](#expect) | Allows the page to be [render-blocked](/en-US/docs/Glossary/Render_blocking) until the essential parts of the document are parsed so it will render consistently. | Link | Not allowed | Not allowed |
29+
| [`expect`](#expect) | When used with [`blocking="render"`](/en-US/docs/Web/HTML/Reference/Elements/link#blocking), allows the page to be [render-blocked](/en-US/docs/Glossary/Render_blocking) until the essential parts of the document are parsed so it will render consistently. | Link | Not allowed | Not allowed |
3030
| [`help`](#help) | Link to context-sensitive help. | Link | Link | Link |
3131
| [`icon`](#icon) | An icon representing the current document. | External Resource | Not allowed | Not allowed |
3232
| [`license`](#license) | Indicates that the main content of the current document is covered by the copyright license described by the referenced document. | Link | Link | Link |

files/en-us/web/html/reference/elements/link/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,12 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Reference/Glo
175175
</table>
176176

177177
- `blocking`
178-
- : This attribute explicitly indicates that certain operations should be blocked on the fetching of an external resource. It must only be used when the `rel` attribute contains `expect` or `stylesheet` keywords. The operations that are to be blocked must be a space-separated list of blocking tokens listed below.
178+
- : This attribute explicitly indicates that certain operations should be blocked until specific conditions are met. It must only be used when the `rel` attribute contains the `expect` or `stylesheet` keywords. With [`rel="expect"`](/en-US/docs/Web/HTML/Reference/Attributes/rel#expect), it indicates that operations should be blocked until a specific DOM node has been parsed. With [`rel="stylesheet"`](/en-US/docs/Web/HTML/Reference/Attributes/rel#stylesheet), it indicates that operations should be blocked until an external stylesheet and its critical subresources have been fetched and applied to the document. The operations that are to be blocked must be a space-separated list of blocking tokens listed below. Currently there is only one token:
179179
- `render`: The rendering of content on the screen is blocked.
180180

181+
> [!NOTE]
182+
> Only `link` elements in the document's `<head>` can possibly block rendering. By default, a `link` element with `rel="stylesheet"` in the `<head>` blocks rendering when the browser discovers it during parsing. If such a `link` element is added dynamically via script, you must additionally set `blocking = "render"` for it to block rendering.
183+
181184
- [`crossorigin`](/en-US/docs/Web/HTML/Reference/Attributes/crossorigin)
182185
- : This [enumerated](/en-US/docs/Glossary/Enumerated) attribute indicates whether {{Glossary("CORS")}} must be used when fetching the resource.
183186
[CORS-enabled images](/en-US/docs/Web/HTML/How_to/CORS_enabled_image) can be reused in the {{HTMLElement("canvas")}} element without being _tainted_.
@@ -387,7 +390,7 @@ You can find a number of `<link rel="preload">` examples in [Preloading content
387390
### Blocking rendering till a resource is fetched
388391

389392
You can include `render` token inside a `blocking` attribute;
390-
the rendering of the page will be blocked till the resource is fetched. For example:
393+
the rendering of the page will be blocked till the resource and its critical subresources are fetched and applied to the document. For example:
391394

392395
```html
393396
<link blocking="render" rel="stylesheet" href="example.css" crossorigin />

files/en-us/web/html/reference/elements/script/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Reference/Glo
5252
See the [Attribution Reporting API](/en-US/docs/Web/API/Attribution_Reporting_API) for more details.
5353

5454
- `blocking`
55-
- : This attribute explicitly indicates that certain operations should be blocked on the fetching of the script. The operations that are to be blocked must be a space-separated list of blocking tokens listed below.
55+
- : This attribute explicitly indicates that certain operations should be blocked until the script has executed. The operations that are to be blocked must be a space-separated list of blocking tokens. Currently there is only one token:
5656
- `render`: The rendering of content on the screen is blocked.
5757

58+
> [!NOTE]
59+
> Only `script` elements in the document's `<head>` can possibly block rendering. Scripts are not render-blocking by default; if a `script` element does not include `type="module"`, `async`, or `defer`, then it blocks _parsing_, not _rendering_. If such a `script` element is added dynamically via script, you must set `blocking = "render"` for it to block rendering.
60+
5861
- [`crossorigin`](/en-US/docs/Web/HTML/Reference/Attributes/crossorigin)
5962
- : Normal `script` elements pass minimal information to the {{domxref('Window.error_event', 'window.onerror')}} for scripts which do not pass the standard {{Glossary("CORS")}} checks. To allow error logging for sites which use a separate domain for static media, use this attribute. See [CORS settings attributes](/en-US/docs/Web/HTML/Reference/Attributes/crossorigin) for a more descriptive explanation of its valid arguments.
6063
- `defer`

files/en-us/web/html/reference/elements/style/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ In the same manner as `<link>` elements, `<style>` elements can include `media`
4747
This element includes the [global attributes](/en-US/docs/Web/HTML/Reference/Global_attributes).
4848

4949
- `blocking`
50-
- : This attribute explicitly indicates that certain operations should be blocked on the fetching of critical subresources. [`@import`](/en-US/docs/Web/CSS/@import)-ed stylesheets are generally considered as critical subresources, whereas [`background-image`](/en-US/docs/Web/CSS/background-image) and fonts are not. The operations that are to be blocked must be a space-separated list of blocking tokens listed below.
50+
- : This attribute explicitly indicates that certain operations should be blocked on the fetching of critical subresources and the application of the stylesheet to the document. [`@import`](/en-US/docs/Web/CSS/@import)-ed stylesheets are generally considered as critical subresources, whereas [`background-image`](/en-US/docs/Web/CSS/background-image) and fonts are not. The operations that are to be blocked must be a space-separated list of blocking tokens listed below. Currently there is only one token:
5151
- `render`: The rendering of content on the screen is blocked.
52+
53+
> [!NOTE]
54+
> Only `style` elements in the document's `<head>` can possibly block rendering. By default, a `style` element in the `<head>` blocks rendering when the browser discovers it during parsing. If such a `style` element is added dynamically via script, you must additionally set `blocking = "render"` for it to block rendering.
55+
5256
- `media`
5357
- : This attribute defines which media the style should be applied to. Its value is a [media query](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries), which defaults to `all` if the attribute is missing.
5458
- `nonce`

0 commit comments

Comments
 (0)