diff --git a/scripts/critical-css.mjs b/scripts/critical-css.mjs
index 6ca60f9..9cf2ef2 100644
--- a/scripts/critical-css.mjs
+++ b/scripts/critical-css.mjs
@@ -34,7 +34,9 @@ try {
dimensions: [{ width: 1280, height: 720 }],
penthouse: { timeout: 30000 },
});
- writeFileSync(htmlPath, outHtml, 'utf-8');
+ // Ensure _app asset paths stay absolute (critical may rewrite; host-based routing needs /_app/...)
+ const normalized = outHtml.replace(/\.\/_app\//g, '/_app/');
+ writeFileSync(htmlPath, normalized, 'utf-8');
console.log(`Critical CSS inlined in ${htmlPath}`);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
diff --git a/scripts/externalize-inline-script.mjs b/scripts/externalize-inline-script.mjs
index fc1cbf2..a986dea 100644
--- a/scripts/externalize-inline-script.mjs
+++ b/scripts/externalize-inline-script.mjs
@@ -73,15 +73,20 @@ try {
console.log('No SvelteKit inline bootstrap script found in', htmlPath);
process.exit(0);
}
- const content = found.content;
+ let content = found.content;
+ // Bootstrap runs from /_app/immutable/bootstrap.xxx.js; imports like "./_app/immutable/entry/..."
+ // would resolve to /_app/immutable/_app/immutable/entry/... (duplicate). Use directory-relative paths.
+ content = content.replace(/\.\/_app\/immutable\//g, './');
const hash = createHash('sha256').update(content).digest('hex').slice(0, 8);
const filename = `bootstrap.${hash}.js`;
const immutableDir = join(buildDir, '_app', 'immutable');
mkdirSync(immutableDir, { recursive: true });
const scriptPath = join(immutableDir, filename);
writeFileSync(scriptPath, content.trimStart(), 'utf-8');
- const scriptTag = ``;
+ const scriptTag = ``;
html = html.slice(0, found.start) + scriptTag + html.slice(found.end);
+ // Use absolute paths for _app assets so they resolve correctly (host-based routing, redirects)
+ html = html.replace(/\.\/_app\//g, '/_app/');
writeFileSync(htmlPath, html, 'utf-8');
console.log('Externalized SvelteKit bootstrap to', scriptPath);
} catch (err) {