Skip to content

Commit 9d8ad33

Browse files
authored
perf: only have Vite generate relative paths when required (#10287)
1 parent 98506eb commit 9d8ad33

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/violet-dryers-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
perf: only have Vite generate relative paths when required

packages/kit/src/exports/vite/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,14 @@ function kit({ svelte_config }) {
541541
// see the kit.output.preloadStrategy option for details on why we have multiple options here
542542
const ext = kit.output.preloadStrategy === 'preload-mjs' ? 'mjs' : 'js';
543543

544+
// We could always use a relative asset base path here, but it's better for performance not to.
545+
// E.g. Vite generates `new URL('/asset.png', import.meta).href` for a relative path vs just '/asset.png'.
546+
// That's larger and takes longer to run and also causes an HTML diff between SSR and client
547+
// causing us to do a more expensive hydration check.
548+
const client_base = kit.paths.relative || kit.paths.assets ? './' : kit.paths.base || '/';
549+
544550
new_config = {
545-
base: ssr ? assets_base(kit) : './',
551+
base: ssr ? assets_base(kit) : client_base,
546552
build: {
547553
copyPublicDir: !ssr,
548554
cssCodeSplit: true,

0 commit comments

Comments
 (0)