New Subject
Random
Previous
Next
|
優化 JS 程式

Avoiding losing tree builder output

Speculative tree building fails when document.write() changes the tree builder state such that the speculative state after the </script> tag no longer holds when all the content inserted by document.write() has been parsed. However, only unusual uses of document.write() cause trouble. Here are

幾個需要避免的問題:

  • 不要使用造成不平均樹的寫法,例如:<script>document.write("<div>");</script> 要寫成 <script>document.write("<div></div>");</script>
  • 記得不要少寫了結束符號,例如:<script>document.write("<div></div");</script>
  • 不要在寫入的字串中使用 \r ,例如<script>document.write("Hello World!\r");</script>,應該使用 \n 代替<script>document.write("Hello World!\n");</script>
  • Note that writing balanced tags may cause other tags to be inferred in a way that makes the write unbalanced. E.g. <script>document.write("<div></div>");</script> inside the head element will be interpreted as <script>document.write("</head><body><div></div>");</script> which is unbalanced.
  • Don't let the semicolon of a named character reference be the last thing that is written. Due to a bug in Firefox 4 though 10 (fixed in Firefox 11), <script>document.write("foo&nbsp;");</script> causes a speculation failure. However, <script>document.write("&nbsp;foo");</script> is OK.
  • TODO: document.write inside formatting elements.
  • This is a reposted article. [The Source]
  • Keywords : script, write, document, 例如, 使用, unbalanced, state, inside, cause, builder, World, However, Hello, Firefox, 避免, 記得, 要寫成, 結束符號, 少寫, 寫法
0 0
2012-01-12T10:06:00+0000


  • Now, you can post comments by Facebook Account when your Yampiz account was logout or unvariable. whatever, we suggest to post comment by Yampiz Account to get more bounds to join new events of Heyxu
Comment
 
Verify