<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>23526</bug_id>
          
          <creation_ts>2013-10-15 16:51:02 +0000</creation_ts>
          <short_desc>[imports]: blocking DOMContentLoaded while HTML imports are loaded</short_desc>
          <delta_ts>2014-04-15 00:55:37 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Component Model</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>24643</dependson>
          <blocked>20683</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>sigmund</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>adamk</cc>
    
    <cc>dominicc</cc>
    
    <cc>morrita</cc>
    
    <cc>sorvell</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>94788</commentid>
    <comment_count>0</comment_count>
    <who name="">sigmund</who>
    <bug_when>2013-10-15 16:51:02 +0000</bug_when>
    <thetext>Should HTML imports block the DOM content loaded event?

The imports spec says that HTML imports block script tags. Script tags block the DOM content loaded event. So, I made an intuitive leap and thought that, even if I have no script tags on my main HTML document, an import would block that event as well.

I couldn&apos;t find anything about it in the spec, and playing with the native implementation I prove myself wrong. However, I was wondering if we should change that.

Here is a simple example:

index.html:
&lt;html&gt;
&lt;script&gt;
  console.log(&apos;1&apos;);
  window.addEventListener(&apos;DOMContentLoaded&apos;,
      function () { console.log(&apos;2&apos;); });
&lt;/script&gt;
&lt;link rel=&quot;import&quot; href=&quot;other.html&quot;&gt;
     &lt;!-- &lt;script&gt; // this is not empty &lt;/script&gt; --&gt;

other.html:
&lt;script&gt;
  console.log(&apos;3&apos;);
  window.addEventListener(&apos;DOMContentLoaded&apos;,
      function () { console.log(&apos;4&apos;); });
&lt;/script&gt;

Loading index.html will print 1, 2, 3; but commenting out the last line in index.html changes the code to print 1, 3, 2, 4.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94804</commentid>
    <comment_count>1</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2013-10-16 00:50:48 +0000</bug_when>
    <thetext>This change makes sense to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94805</commentid>
    <comment_count>2</comment_count>
    <who name="Steve Orvell">sorvell</who>
    <bug_when>2013-10-16 01:32:42 +0000</bug_when>
    <thetext>I&apos;m in favor of this change as well. I had a similar expectation and was surprised to learn that this was not the case.

If a set of imports loads resources on which a page wants to act, it&apos;s cumbersome to have to listen for load events to fire. It&apos;s also tricky to setup load event listeners since either the onload attribute or an a priori MutationObserver must be used.

In the future, we may want to give imports an async attribute so that they can behave similarly to async scripts.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94806</commentid>
    <comment_count>3</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2013-10-16 03:25:57 +0000</bug_when>
    <thetext>This might be just an implementation bug rather than a spec bug.
Let me see if &lt;link rel=stylesheet&gt; blocks the DOMContentLoaded event.
If it doesn&apos;t and &lt;link rel=import&gt; should, the spec should be explicit about that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103848</commentid>
    <comment_count>4</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2014-04-15 00:06:04 +0000</bug_when>
    <thetext>Discussed briefly in the last F2F. 
http://www.w3.org/2014/04/11-webapps-minutes.html

And I didn&apos;t see any objection. rniwa mentioned that this is similar to &lt;script defer&gt;, that is good point.

I removed the FIXME section as this behavior happened to be captured in the spec already.

https://github.com/w3c/webcomponents/commit/0cb84f294070821976de57a4029a506473375107</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103851</commentid>
    <comment_count>5</comment_count>
    <who name="Morrita Hajime">morrita</who>
    <bug_when>2014-04-15 00:55:37 +0000</bug_when>
    <thetext>On second thought, I found that this should be rather handled by load event
instead of DOMContentLoaded event. That is because:

- Imports can be nested and have unpredictable delay, that is not what
  users of DOMClientLoaded expect. &lt;script defer&gt; is counter example of this,
  but I think it is mainly for compatibility reason - Script has been expected
  to be loaded before the parser ends.
- HTML standard has a hook for load event [1] but doesn&apos;t have one for DOMContentLoaded. It is not expected to be extensible and the load event is more generic extension point. 

We might want an event for signaling import readiness, or we could use some
promise based API for waiting the readiness, that is proposed at Bug 25007.

I landed the change that employs the |load| hook and eliminating a monkey patch for waiting DOMContentLoaded [2]. Less of monkey patch indicates that this is saner way to go.

[1] http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#the-end
[2] https://github.com/w3c/webcomponents/commit/b5ca1fbf683f8c7bbc0ff6b097476b18f1e25e22</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>