Skip to content

Support blocking execution order for HTMLScriptElement (document-order script execution) #250

@yorkie

Description

@yorkie

Feature request: Support blocking script execution for HTMLScriptElement according to document order, matching classic browser behavior.

Background
Currently, JSAR should ensure that scripts in the document (that are not type="module", async, or defer) are executed strictly in the order they appear in the DOM, regardless of download completion order.

Expected behavior & requirements

  • Scripts should be executed in the order they appear in the document.
  • If multiple scripts (a, b, c) initiate loading requests simultaneously, the execution must wait for all previous scripts to finish before proceeding, even if later scripts download faster.
  • Scripts with async, defer, or type="module" are excluded from this blocking order.

Implementation proposal

  • Introduce an execution queue in the browsing context. This queue tracks pending script elements for execution order, but does not handle the actual loading or execution logic itself.
  • HTMLScriptElement should use this execution queue to ensure scripts are run in the correct order, regardless of when each finishes downloading.
  • The execution queue only manages order, not the details of loading/execution.

Points to consider

  • Asynchronous loading is still permitted, but execution must wait for previous scripts to be loaded and executed before running subsequent scripts.
  • Example: If scripts a and b are downloading in parallel, but b finishes first, b must wait for a to finish loading and executing before it executes.
  • The execution queue is responsible only for blocking and order management, not loading or execution details.

This change would bring HTMLScriptElement execution behavior in JSAR in line with browser standards and improve compatibility with web content relying on strict script execution order.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions