Loading...
<script>
const res = await fetch('/config.json');
const config = await res.json();
</script><script type="module">
const res = await fetch('/config.json');
const config = await res.json();
</script>Top-level await works only in modules, so the classic script throws a syntax error.
await in a classic script and getting a syntax error.<script type='module'>.await is not used in modules that many others import, because every importing module waits for it.try...catch, so one rejected promise does not break the whole module graph.It delays only modules that import this one, until its promise settles. Modules that do not depend on it keep loading and can run.
No. With top-level await, importing modules wait for the result; with an async IIFE, they run before the async work finishes.
The module fails to evaluate, and every module that imports it fails with the same error.