jddxf
jddxf

Reputation: 1990

How does a script with an async attribute get executed after it's been fetched

According to the HTML spec, with <script async>, fetching is parallel to parsing but once it finishes parsing is interrupted to execute the script. However, I didn't find anything in the spec that mentions how parsing is interrupted. While there's an explanation of how that's done for parsing-blocking scripts, I'm curious about the mechanism for <script async>.

Upvotes: 1

Views: 127

Answers (1)

LemonCool
LemonCool

Reputation: 1260

the specifications are generic on purpose to highlight the intended behavior and the end-user general expectation, cause most browser will implement this mechanism differently and will vary also based on the platform it will run, e.g.:

  • Linux: using select/poll capabilities
  • UNIX-Like: kqueue
  • Window: Async capabilities of the OS

In general the mechanism will implements events, once the "parsing event" is done, trigger new event "script execution" to be executed (event queue based as mentioned above), this are low level mechanism exposed to the browser, so you might have browser that don't support it on certain os(even if the same browser), for example that tag will be ignored in firefox on the raspberry pi platform.

Upvotes: 1

Related Questions