Reputation: 2872
I developed a site with sveltekit:svelte: (@sveltejs/kit": "1.0.0-next.95). The articles are written markdown so I am using mdsvex for the conent.
I deployed the site both with adapter vercel and adapter static in cloudflare pages.
Both scripts run fine and I am just trying to understand the benefits of using the severless function with vercel adapter vs running the site as a static export with the adapter static that would work anywhere (including vercel even without their adapter that has a severless function).
Upvotes: 4
Views: 2796
Reputation: 5482
adapter-static will render your entire site as a collection of static files, i.e. HTML, CSS, and JS. adapter-vercel will use Vercel's serverless functions for dynamic server rendering.
If your entire site can be prerendered, use adapter-static; otherwise, you can go with adapter-vercel. From the SvelteKit docs:
It's likely that at least some pages of your app can be represented as a simple HTML file, since they contain no dynamic or user-specific data. These pages can be prerendered by your adapter.
If your entire app is suitable for prerendering, you could use adapter-static, which will generate HTML files for every page, plus additional files that are requested by load functions in those pages.
The docs also talk about how to know when a page is prerenderable:
The basic rule is this: for a page to be prerenderable, any two users hitting it directly must get the same content from the server.
In other words, any app that involves user sessions or authentication is not a candidate for adapter-static, even if individual pages within an app are suitable for prerendering.
Note that you can still prerender pages that load data based on the page's parameters, like our src/routes/blog/[slug].svelte example from earlier. The prerenderer will intercept requests made inside load, so the data served from src/routes/blog/[slug].json.js will also be captured.
You can still use adapter-vercel for a completely static site, but the server rendering of your pages will happen at runtime instead of build time, which could be slower and/or more expensive.
Upvotes: 5