Sveltekit 无服务器适配器,如 Vercel 或静态适配器?
Sveltekit serverless adapter like vercel or adapter static?
我用 sveltekit:svelte 开发了一个站点:(@sveltejs/kit": "1.0.0-next.95)。这些文章是用 markdown 编写的,所以我使用 mdsvex 作为内容。
我在 cloudflare 页面中部署了带有适配器 Vercel 和静态适配器的站点。
两个脚本 运行 都很好,我只是想了解将无服务器功能与 Vercel 适配器一起使用与 运行 将站点作为静态导出与静态适配器一起工作的好处任何地方(即使没有具有无服务器功能的适配器,也包括 Vercel)。
adapter-static will render your entire site as a collection of static files, i.e. HTML, CSS, and JS. adapter-vercel 将使用 Vercel 的无服务器功能进行动态服务器渲染。
如果您的整个网站都可以预呈现,请使用静态适配器;否则,您可以使用 adapter-vercel。来自 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.
文档还讨论了如何知道页面何时 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.
您仍然可以将 adapter-vercel 用于完全静态的站点,但是页面的服务器呈现将在运行时而不是构建时发生,这可能会更慢 and/or 更昂贵。
我用 sveltekit:svelte 开发了一个站点:(@sveltejs/kit": "1.0.0-next.95)。这些文章是用 markdown 编写的,所以我使用 mdsvex 作为内容。
我在 cloudflare 页面中部署了带有适配器 Vercel 和静态适配器的站点。
两个脚本 运行 都很好,我只是想了解将无服务器功能与 Vercel 适配器一起使用与 运行 将站点作为静态导出与静态适配器一起工作的好处任何地方(即使没有具有无服务器功能的适配器,也包括 Vercel)。
adapter-static will render your entire site as a collection of static files, i.e. HTML, CSS, and JS. adapter-vercel 将使用 Vercel 的无服务器功能进行动态服务器渲染。
如果您的整个网站都可以预呈现,请使用静态适配器;否则,您可以使用 adapter-vercel。来自 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.
文档还讨论了如何知道页面何时 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.
您仍然可以将 adapter-vercel 用于完全静态的站点,但是页面的服务器呈现将在运行时而不是构建时发生,这可能会更慢 and/or 更昂贵。