Skip to content

Instantly share code, notes, and snippets.

@domfarolino
Created January 3, 2019 20:25
Show Gist options
  • Save domfarolino/3fa29b31800e2203c8ce12b22cf8eba9 to your computer and use it in GitHub Desktop.
Save domfarolino/3fa29b31800e2203c8ce12b22cf8eba9 to your computer and use it in GitHub Desktop.

Link rel=stylesheet

Somehow make Link rel=stylesheet's [fetch and process the linked resource] algorithm do the following:

  • If el [contributes a script-blocking style sheet], increment el's [node document]'s [script-blocking style sheet counter by one.

(^Either by passing some custom steps to [default fetch and process the linked resource], or overriding the algorithm)

The [process the linked resource] algorithm for this type of resource is as follows, given el, success, and response:

  1. ...
  2. Queue a task to:
    1. Fire events accordingly
    2. [Create] a [CSS style sheet] whose properties
    3. If el [contributes a script-blocking style sheet]:
      1. Assert: el's [node document]'s script-blocking style sheet counter is greater than 0.
      2. Decrement el's [node document]'s script-blocking style sheet counter by one.

4.2.6 The style element

The [update a style block algorithm is as follows]:

  1. Let element be the [style] element.
  2. ...
  3. If element [contributes a script-blocking style sheet], increment element's [node document]'s [script-blocking style sheet counter] by one.
  4. [Create] a [CSS style sheet] with the following properties...

Once the attempts to obtain the style sheet's critical subresources are complete, of if the style sheet had no critical subresources:

  1. Fire events accordingly.
  2. If element [contributes a script-blocking style sheet]:
    1. Assert element's [node document]'s [script-blocking style sheet counter] is greater than 0.
    2. Decrement element's [node document]'s [script-blocking style sheet counter] by one.

4.2.7 Interactions of styling and scripting

An element el in the context of a [Document] of an [HTML parser] or [XML parser] [contributes a script-blocking style sheet] if the following are true:

  • el was created by that Document's parser.
  • el is either a [style] element, or a [link] element that was an [external resource link that contributes to the styling processing model] when the element was created by the parser.
  • If el is a [link] element, it's [media] attribute's value [matches the environment].
  • el's style sheet was enabled when the element was created by the parser. [not so sure about this, since link elements don't create style sheets until the resource is loaded]
  • The last time the [event loop] reached [step 1], the element's [root] was that [Document].
  • The user agent hasn't given up on that particular style sheet yet. A user agent may give up on a style sheet at any time.

A [Document] has a script-blocking style sheet counter, which is a number, initially 0.

A [Document] has a style sheet that is blocking scripts if its script-blocking style sheet counter is greater than 0.

A [Document] ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment