Closed jsnajdr closed 1 year ago
Hmm, perhaps we should be using defer
instead? We don't really want to wait on everything else being loaded either after all.
In this case, where all the code is in the DOMContentLoaded
/load
listener, defer
wouldn't make much difference. defer
script are guaranteed to be executed only after "the document has finished parsing", immediately before DOMContentLoaded
. We'd be waiting for everything else to be loaded anyway.
Also, at the time when the listener runs, the a#commit-snapshot-link
element must already be present in the document.
So, yes, both combinations, DOMContentLoaded
+ defer
, and load
+ async
, are correct (but not the DOMContentLoaded
+ async
one!), but they do almost exactly the same thing.
That's not entirely true. We don't have to wait for things that delay the load event, such as images.
We don't have to wait for things that delay the load event, such as images.
Oh, this is a good point -- I thought that the DOMContentLoaded
and load
events are very close together, but they aren't. We're waiting until all the resources that are neither parser-blocking nor render-blocking get loaded.
I'll rework both patches to use defer
instead, and keep the DOMContentLoaded
listeners.
This PR has been transformed into one that merely changes the comment that describes how the script should be included. All other work is now done in https://github.com/whatwg/html/pull/9297.
For the non-HTML standards https://github.com/speced/bikeshed-boilerplate/blob/main/boilerplate/whatwg/header.include will have to be patched. Do you want to take that on as well?
Do you want to take that on as well?
Yes, done in https://github.com/speced/bikeshed-boilerplate/pull/40.
Thanks for following through on everything here @jsnajdr! Each specification will need a new commit before this change becomes part of it, but hopefully that doesn't take too long overall.
Fixing what I believe is a little bug in the
commit-snapshot-shortcut-key.js
script. Inhtml.spec.whatwg.org
it's loaded with theasync
flag, which means it can run after theDOMContentLoaded
event has fired. The listener that sets up the keyboard shortcut will never run in that case. Only a script withdefer
is guaranteed to run beforeDOMContentLoaded
.The fix uses the
load
event instead, which is fired only after even theasync
scripts are finished running.In the spec, this is the place where all the
async
scripts are flushed, and it runs between theDOMContentLoaded
andload
events.I found this when trying to learn what exactly the difference between
async
anddefer
is.