DOMContentLoaded waits for slow async script when deferred script is in document

RESOLVED FIXED in Firefox 41

Status

()

RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: koch, Assigned: Gijs)

Tracking

(Depends on: 1 bug, {regression})

33 Branch
mozilla41
x86_64
Windows 7
regression
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox41 fixed)

Details

Attachments

(1 attachment)

(Reporter)

Description

4 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
Build ID: 20141113143407

Steps to reproduce:

I have an HTML file containing two script elements: one with async, one with defer. Response for the deferred script is quick, the response for the async script starts after some seconds.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>async</title>
    <script src="uick_defer.js" defer></script>
    <script src="lame_async" async></script>
  </head>
  <body>
  </body>
</html>


Actual results:

DOMContentLoaded watis until the async script is available (or executed, I don't know). When I remove the script with defer, DOMContentLoaded does not wait for the async script.


Expected results:

DOMContentLoaded does not wait for the async script. This happened with older versions of Firefox (< 30?) and happens in e.g. Chrome.
(Reporter)

Updated

4 years ago
Summary: DOMContentLoaded waits for async script → DOMContentLoaded waits for lame async script when deferred script is in document

Comment 1

4 years ago
Could you attach a simple self-contained testcase (or public URL) to show up the issue, please.
Flags: needinfo?(koch)
Keywords: testcase-wanted
(Assignee)

Updated

4 years ago
Component: Untriaged → Untriaged
Keywords: regression, regressionwindow-wanted
Product: Firefox → Core
Summary: DOMContentLoaded waits for lame async script when deferred script is in document → DOMContentLoaded waits for slow async script when deferred script is in document
(Reporter)

Comment 2

4 years ago
Testcases: <http://waldbaer.leute.server.de/DOMContentLoaded_defer_async/>

The behaviour in the combined cases (both async and defer) is wrong. For comparision, I added single cases (only async or defer) as well.
Flags: needinfo?(koch)

Comment 3

4 years ago
Running "quick defer, lame async" of the Testcases

before 9acc076ad18f Bug 688580:
  DOMContentLoaded -> "quick" -> "lame"

after 9acc076ad18f Bug 688580:
  "quick" -> "lame" -> DOMContentLoaded

Google Chrome:
  "quick" -> DOMContentLoaded -> "lame"


Bug 688580 something wrong?
Blocks: 688580
Flags: needinfo?(bugs)

Updated

4 years ago
Component: Untriaged → HTML: Parser

Updated

4 years ago
Keywords: regressionwindow-wanted, testcase-wanted

Comment 4

4 years ago
Came across this bug in FF Developer Channel. Why is it unconfirmed?
(In reply to iliakan from comment #4)
> Came across this bug in FF Developer Channel. Why is it unconfirmed?

In practice, we often don't bother marking bugs as confirmed, and being confirmed or not does not have a large impact on how people deal with the bug.
Status: UNCONFIRMED → NEW
Ever confirmed: true

Updated

4 years ago
Flags: needinfo?(bugs)
(Assignee)

Comment 6

4 years ago
Created attachment 8612253 [details]
MozReview Request: Bug 1104732 - having deferred scripts shouldn't cause async scripts to delay domcontentloaded, r?smaug

Bug 1104732 - having deferred scripts shouldn't cause async scripts to delay domcontentloaded, r?smaug
(Assignee)

Comment 7

4 years ago
Comment on attachment 8612253 [details]
MozReview Request: Bug 1104732 - having deferred scripts shouldn't cause async scripts to delay domcontentloaded, r?smaug

By my "one random patch a day keeps the doctor away" maxim, here's today's. I *think* this is what we want. I added a test and that seems to work. I also checked the reporter's testcase which also seems fixed by this patch. Olli, does this look sane to you?
Attachment #8612253 - Flags: review?(bugs)
(Assignee)

Comment 8

4 years ago
Comment on attachment 8612253 [details]
MozReview Request: Bug 1104732 - having deferred scripts shouldn't cause async scripts to delay domcontentloaded, r?smaug

Bug 1104732 - having deferred scripts shouldn't cause async scripts to delay domcontentloaded, r?smaug
Attachment #8612253 - Flags: review?(bugs) → review+
(Assignee)

Comment 11

4 years ago
I had to change this testcase because it oranged intermittently. async scripts aren't guaranteed to load after DOMContentLoaded - depending on timing, they could load before. This means we can't meaningfully assert much beyond that they should have loaded before onload. Test change:

remote:   https://hg.mozilla.org/integration/mozilla-inbound/rev/bea6758824d9

I landed this because the tree got closed because of the intermittent, but I'd like to have feedback if there's something I'm missing, ie whether there *is* a way to test for this reliably...
Flags: needinfo?(bugs)
Hmm, indeed testing this reliably is hard since async may or may not be loaded before DOMContentLoaded, depending on what kind of network packages parser gets and what not.
Don't have good ideas now how to improve the test.

or perhaps, what if you had something like
<script>
  document.write("<script async src='file_async_bug1104732.sjs"'></script>");
</script>
right at the end of the html file. That might make the test reliable enough.
Flags: needinfo?(bugs)
(Assignee)

Updated

4 years ago
Depends on: 1169660
(Assignee)

Comment 13

4 years ago
Filed bug 1169660 for improving the test further.
Assignee: nobody → gijskruitbosch+bugs
Status: NEW → ASSIGNED
https://hg.mozilla.org/mozilla-central/rev/991331d28d8e
https://hg.mozilla.org/mozilla-central/rev/bea6758824d9
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
status-firefox41: --- → fixed
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
You need to log in before you can comment on or make changes to this bug.