use fetch in +layout.server.ts load function without including the fetched url in client side code #9384
-
I am fetching data from a third party api using the load function's fetch in +layout.server.ts and using that data in +page.server.ts But the url being fetched is included in the uses dependencies array in the response html even though it is never being called in client side |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
The problem is likely due to the server-side rendering (SSR) that SvelteKit provides. When the page is rendered on the server, the code in +page.server.ts is executed and the data from the API is included in the response HTML. When the page is rendered in the browser, the data from the API is not fetched again and the URL will still be included in the HTML. To prevent this, you can configure the page to not be rendered on the server with the SSR option in the page options. |
Beta Was this translation helpful? Give feedback.
-
Can you provide a repro? I spot-checked my site that fetches data from an external API in |
Beta Was this translation helpful? Give feedback.
-
The issue is occurring when data is being fetched from an external api in A live version is deployed here if you go to view sources on that page you can find the jsonplaceholder url from which we are fetching the data |
Beta Was this translation helpful? Give feedback.
-
this was fixed in 1.18.0 release thanks for the help |
Beta Was this translation helpful? Give feedback.
this was fixed in 1.18.0 release thanks for the help