CKTIS / HTML
async — run a script when ready
`async` allows fetching alongside document processing and running a script when ready without guaranteeing execution order.
Version: HTML Living Standard
Syntax
<script async src="/feature.js"></script>It is boolean: async="false" still enables it. For external classic scripts execution can occur before parsing finishes; running the code still occupies the main thread. Do not use it for dependent scripts that require document order.
For module scripts it concerns readiness of the module and its dependencies. It does not give this behavior to an inline classic script. With defer also present, asynchronous execution wins. DOMContentLoaded does not wait for these scripts; this is not the JavaScript async-function keyword.
The example places a slow file before a fast file. Its local receiver deliberately holds the first until the second executes, producing fast → slow. That proves document order is not enforced, not a promised order under arbitrary network conditions.
Examples
<!doctype html><meta charset="utf-8"><output id="result"></output>
<script>
// Local /slow.js calls record('slow'); /fast.js calls record('fast').
// The test receiver releases slow.js only after fast.js has executed.
window.order = [];
window.record = name => {
window.order.push(name);
if (window.order.length === 2) document.querySelector('#result').textContent = window.order.join(' -> ');
};
</script>
<script async src="/slow.js"></script>
<script async src="/fast.js"></script>Result
fast -> slow
The exact result comes from deliberately ordered local responses; real fetching can produce another order.