feat: add version polling and auto-reload on deploy

- Enable kit.version.pollInterval (60s) so SvelteKit detects new
  deploys via version.json
- Add beforeNavigate guard that forces a full page reload when a
  new version is detected, preventing stale client-side state
- Preload fonts, JS, and CSS for faster initial paint
This commit is contained in:
2026-02-22 19:24:18 +01:00
parent ed52963bf5
commit 072c9dc934
3 changed files with 15 additions and 2 deletions

View File

@@ -54,5 +54,7 @@ export const handle: Handle = async ({ event, resolve }) => {
}
}
return resolve(event);
return resolve(event, {
preload: ({ type }) => type === 'font' || type === 'js' || type === 'css'
});
};

View File

@@ -3,6 +3,8 @@
import Header from '$lib/components/layout/Header.svelte';
import Footer from '$lib/components/layout/Footer.svelte';
import { page } from '$app/stores';
import { updated } from '$app/stores';
import { beforeNavigate } from '$app/navigation';
import type { Snippet } from 'svelte';
interface Props {
@@ -13,6 +15,12 @@
let { data, children }: Props = $props();
const canonicalUrl = $derived(`https://marktvogt.de${$page.url.pathname}`);
beforeNavigate(({ willUnload, to }) => {
if ($updated && !willUnload && to?.url) {
location.href = to.url.href;
}
});
</script>
<svelte:head>

View File

@@ -3,7 +3,10 @@ import adapter from '@sveltejs/adapter-node';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter()
adapter: adapter(),
version: {
pollInterval: 60_000
}
}
};