Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion manuscript/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ nextTitle: Serializing
---
# Chapter 4. Scripting complications

Implementations of HTML that do not need to support executing scripts are exempt from various complications, in particular the necessary hoops for `document.write()`. Browsers that wish to be compatible with the vast majority of the web will have to support scripting, and jump through the hoops with elegance.

## Revised overview of the HTML parser

TODO
Because of `document.write()`, the {% ref "parser", "overview of the HTML parser" %} in {% ref "parser", "Chapter 3. The HTML parser" %} is incomplete.

The HTML standard has this diagram:

![]()

## `document.write()`

A script in an inline `<script>` is executed by the tree builder, while handling the `</script>` end tag. The parser is blocked until the script has completed. If the script calls `document.write()`, the characters passed in are added to the parser's input stream. The algorithm for `document.write()` makes the HTML parser consume those characters, before returning (i.e., before allowing the next statement in the script run).

What if those characters are `<script>...</script>`? Then you have to execute that script before the `document.write()` can return. What if that script `document.write()`s another script? Yes, I suppose you get the picture. (TODO discuss nested document.write limit.)

TODO

### Blocking the parser
Expand All @@ -22,6 +32,8 @@ TODO

TODO

## The scripting flag and the `noscript` element

## Other parser APIs

TODO
Expand Down