Reputation: 479
I'm using SvelteKit to build a static website with the static adapter for server rendering. I've noticed that in the generated HTML files, there's a script that fetches the same data that's already included in the page. For example, if I have a page listing blog posts and I fetch the posts data in the server-side load function, SvelteKit still includes a script to fetch the same data when rendering the HTML.
In my +page.ts file I am doing the following:
import type { Post } from '$lib/types';
export async function load({ fetch }) {
const response = await fetch('../api/posts');
const posts: Post[] = await response.json();
return { posts };
}
export const prerender = true;
I'm confused about the purpose of this redundant script and whether it's necessary for static sites where all the data is pre-rendered. Is there a way to configure SvelteKit or the static adapter to prevent this redundant data fetching script from being included in the HTML output?
<script type="application/json" data-sveltekit-fetched data-url="/api/posts">
{"status:200, ... all the data ...
</script>
Any insights or suggestions on how to address this issue would be greatly appreciated. Thanks in advance!
Upvotes: 3
Views: 89