Deploying a SvelteKit blog to traditional FTP hosting
How to generate a fully static site with SvelteKit and adapter-static and publish it to ordinary shared hosting over FTP.
You don't need serverless infrastructure to have a blazing-fast site: shared hosting costing a few euros a year is more than enough, as long as the site is static.
Why static generation
With Static Site Generation every page is rendered only once, at build time. The server only has to return ready-made HTML, CSS and JavaScript files:
- no Node.js runtime on the server;
- minimal response times (very low TTFB);
- a smaller attack surface;
- negligible hosting costs.
Configuring adapter-static
In SvelteKit 3 the configuration is passed directly to the Vite plugin:
import adapter from '@sveltejs/adapter-static';
import { sveltekit } from '@sveltejs/kit/vite';
export default defineConfig({
plugins: [sveltekit({ adapter: adapter({ fallback: '404.html' }) })]
});And in the root layout we enable prerendering for every route:
export const prerender = true;
export const trailingSlash = 'always';With trailingSlash = 'always' each page is written as folder/index.html, a format that any web server can serve without rewrite rules.
Uploading over FTP
After npm run build the build/ folder contains the whole site. You can upload it with FileZilla or, better, automate everything with a GitHub Action.
Tip: always upload the
.htaccessfile too: it sets up the custom 404 page and asset caching.