Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to prevent redundant data fetching script (application/json) in static adapter-generated HTML?

$
0
0

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!


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>