Closed Bug 521391 Opened 15 years ago Closed 6 years ago

[HTML5] Provide a dev doc explaining how to avoid speculation failures

Categories

(Developer Documentation Graveyard :: HTML, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: hsivonen, Assigned: hsivonen)

Details

(Keywords: access, Whiteboard: u=webdev p=0 c=HTML)

Bug 482919 will introduce speculative parsing to the HTML5 parser. Web authors who care about the load times of their pages should avoid the kind of document.write() use that makes speculations fail.

Need to provide a DevMo article that explains what the pitfalls are.

 * Don't put "\r" at the end of your last document.write() in a script. (Hopefully people who document.write() line breaks use "\n" anyway.)

 * Don't write unbalanced trees. <script>document.write("<div>");</script> is bad.

 * Don't document.write() and unfinished token. <script>document.write("<div ");</script> is bad.

 * Need to explain the situation where formatting elements interfere. That is the cases where <b><script>document.write("...");</script></b> is bad.

 * Don't insert from script or document.write() a <base> element. (Doesn't cause speculative parse to fail but causes speculative loads to fail.)
Priority: -- → P2
Priority: P2 → P3
The page says <script>document.write("<div></div>");</script> is good. ALMOST.
<script>document.write("<div><\/div>");</script> is good.
Remember, the parser stops scanning when it reaches the first "</".
(In reply to comment #2)
> The page says <script>document.write("<div></div>");</script> is good.
> ALMOST.
> <script>document.write("<div><\/div>");</script> is good.
> Remember, the parser stops scanning when it reaches the first "</".

Not so. See http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#script-data-end-tag-open-state and the related states.
Component: Documentation Requests → Documentation
Component: Documentation → General
Product: Mozilla Developer Network → Developer Documentation
Whiteboard: u=webdev p=0
Component: General → HTML
Keywords: access
Whiteboard: u=webdev p=0 → u=webdev p=0 c=HTML
FIXED per comment 1.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.