[Webkit-unassigned] [Bug 38146] document.write is not synchronous

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat May 1 14:11:36 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=38146





--- Comment #5 from Joseph Pecoraro <joepeck at webkit.org>  2010-05-01 14:11:35 PST ---
It was asked that I do some more testing and impact research:

> I think matching other browsers is cool and a good enough reason
> to do something ... but more testing / compat impact info would be
> really valuable

Here goes:


How this patch affects behavior:
--------------------------------

  1. Typical page load times should be unaffected. This is because
  any document.write which happens in a <script> on page load time
  will increment m_executingScript and cause the document.write to
  be synchronous anyways.

  2. Entire pages written with document.write (where it writes over
  the existing page) will be affected. I haven't seen usage of this,
  and it appears to be discouraged at all of the above articles.

  3. However, in those cases we will match the spec and other
  browsers. I have tested on Mac OS X 10.6 - Firefox 3.6,
  Chrome 5.0.342.9, Opera 10.53


Test Cases:
-----------

I tested the state of the tokenizer right before it makes its decision to yield
or not. I show below how the state of the tokenizer will change, and whether or
not that will change behavior (as I mentioned above).

  1. Inline <script> document.write on page load

      state.loadingExtScript(): false
      state.forceSynchronous(): false  [will become true, but no change]
      m_executingScript       : true
      allowedYield            : false

  2. External <script src="..."> with document.write on page load

      state.loadingExtScript(): true
      state.forceSynchronous(): false  [will become true, but no change]
      m_executingScript       : true
      allowedYield            : false

  3. document.write after page is done loading

      state.loadingExtScript(): false/true
      state.forceSynchronous(): false  [will become true, changes behavior]
      m_executingScript       : true
      allowedYield            : false

Case 3 is what I mention above. Below is some research I did to see how this
could affect things. For instance the "Public perception" or "what the web is
saying" about document.write:


Top Google Hits:
----------------

- http://javascript.about.com/library/blwrite.htm
Advises use only while the page is loading, because otherwise it writes over
the existing page content. Also, document.write doesn't apply to XML and
therefore XHTML.


-
http://www.sitepoint.com/blogs/2007/07/11/insert-in-place-without-documentwrite/
Advises DOM creation instead of document.write.

>   And there you have it – a simple but elegant way of inserting
>   content in place, removing the last vestige of need for
>   document.write!


-
http://java-programming.suite101.com/article.cfm/javascript_documentwrite_tutorial
2008 article describing how to use it and why it is useful. This article does
not mention any alternatives. It does warn that usage should be restricted to
page loading:

>  The document.write command must be carried out during the loading of
>  the page. So, if it is attached to any event that executes after the
>  page has loaded, then the whole page will be replaced with the
>  contents of the document.write command.

However you can still find recent articles proposing document.write as useful:

- http://www.joshstauffer.com/ways-to-use-document-write/

>  The document.write command is a standard, yet powerful, JavaScript
>  command for writing output to a page. In this article I’ve outline
>  3 ways to use document.write statements.


Common document.write usage across the Web:
-------------------------------------------

- Google Analytics
http://code.google.com/apis/analytics/docs/tracking/gaTrackingOverview.html
The "traditional" snippet used across the web for free analytics uses
document.write. However its usage should be unaffected by this patch. Its also
worth noting that the newer asynchronous tracking snippet is described as "an
improved way", and this does not use document.write.


Summary:
--------

I don't see anyone recommending usage of document.write after page load. Its
possible that I just haven't seen it. Its arguably more likely that
document.implementation.createHTMLDocument and write() on the newly created
document could be used on some sites, but "document.implementation" is not
available on all browsers and in those cases we would start matching other
browser's behavior and give the results users would expect by matching WebKit's
own behavior of document.write on page loads.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list