Skip to content

Commit

Permalink
Only load and wait for JavaScript in main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Jan 10, 2024
1 parent 50f3918 commit 9b9ba62
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ function runScripts() {
let wait = Promise.resolve();
for (const script of Array.from(document.scripts)) {
if (script.dataset.astroExec === '') continue;
const type = script.getAttribute('type');
if (type && type !== 'module' && type !== 'text/javascript') continue;
const newScript = document.createElement('script');
newScript.innerHTML = script.innerHTML;
for (const attr of script.attributes) {
if (attr.name === 'src') {
const p = new Promise((r) => {
newScript.onload = r;
newScript.onload = newScript.onerror = r;
});
wait = wait.then(() => p as any);
}
Expand Down

0 comments on commit 9b9ba62

Please sign in to comment.