> ## Content Index
> Fetch the complete content index at: https://www.webzenith.news/llms.txt
> Use this file to discover other available public pages before exploring further.

# Sveltekit — Streaming SSR
- URL: https://www.webzenith.news/sveltekit-streaming-ssr/
- Published: 2023-11-22T11:33:42.000Z
- Updated: 2026-10-31T04:31:56.000Z
- Description: I’ve been working on a project with Sveltekit with Supabase and DrizzleOrm. Everything worked fine when thing were running locally .All…
- Author: Mohammed Anas
- Tags: Sveltekit, #anasmohammed361, UX, Server Side Rendering, Data Streaming, Performance, #Migrated-1793421108672, #Import 2026-10-31 04:31

I’ve been working on a project with Sveltekit with [Supabase](https://supabase.com/?ref=webzenith.news) and [DrizzleOrm](https://orm.drizzle.team/?ref=webzenith.news). Everything worked fine when thing were running locally .All pages worked seamlessly with SSR.

But Once i pushed it to production, i was seeing 1–2 seconds delay with page navigation which is really not acceptable from a end user pov , it really kills the user experience.

If i opted for CSR it is going to kill SEO, So i chose to stream some of my data which is not important for initial page load , So we get immediate resoponse from the server , which is good for UX and at the same time i dont want to setup api routes which needs more Javascript on the client.

At the same time you get proper type safety when using Streaming , comparing it with using your own API routes

---

### Setup Streaming in Sveltekit

***This is for sveltekit v1 , v2 was relesed recently , if you wanna use it with v2 take a look at streaming*** [***here***](https://kit.svelte.dev/docs/migrating-to-sveltekit-2?ref=webzenith.news#top-level-promises-are-no-longer-awaited)

We have created a sample sveltekit project, with two routes , **/ssr** and **/streaming .**

Lets emulate a costly computation with this code on both the endpoints server load

```typescript
const promise = new Promise<number>((res) => { 
    setTimeout(() => { 
      res(Math.random()); 
    }, 3000); 
  });
```

This is a simple promise which resolves after 3 seconds , Lets setup the basic routes

### SSR Route

```typescript
//+page.server.ts 
import type { PageServerLoad } from "./$types"; 
 
export const load: PageServerLoad = async () => { 
  const promise = new Promise<number>((res) => { 
    setTimeout(() => { 
      res(Math.random()); 
    }, 3000); 
  }); 
  return { promise }; 
};
```

```xml
// +page.svelte 
<script lang="ts"> 
    export let data 
</script> 
<p>{data.promise}</p>
```

The top level promises are automatically awaited by sveltekit , you don’t need to manually await the data.

### Streaming Route

```typescript
//+page.server.ts 
import type { PageServerLoad } from './$types'; 
 
export const load:PageServerLoad = async () => { 
    const promise = new Promise<number>((res)=>{ 
        setTimeout(()=>{ 
            res(Math.random()) 
        },3000) 
    }) 
    return { 
        stream:{ 
            promise 
        } 
    } 
};
```

```xml
// +page.svelte 
<script lang="ts"> 
    export let data; 
    $:({stream:{promise}}=data) 
</script> 
 
{#await promise} 
    <p>wait</p> 
{:then data}  
    <p>{data}</p> 
{/await}
```

If you want you use streaming in sveltekit , you need to return a promises as a nested object field , as we mentioned that top level responses are automatically awaited by sveltekit.

---

If we setup a basic navigation page and try to navigate to that page, you can see that , the SSR page take 3 seconds to render on the server and navigate while the streaming page gets rendered instantly.

[Try it out here](https://stackblitz.com/~/github.com/anasmohammed361/sveltekit-streaming-example?ref=webzenith.news)

Frameworks like Next.Js has built in support for loading Ui , and Streaming Responses, But fortunately setting it up in Sveltekit is relatively simple and straight forward.

> Do note that you might need to setup a loading ui when the promise is awaited.

If you want to check out the project , take a look at this [gitub repo](https://github.com/anasmohammed361/sveltekit-streaming-example?ref=webzenith.news).

You can also find the official sveltekit docs [here](https://kit.svelte.dev/docs/load?ref=webzenith.news#streaming-with-promises).

### Conclusion

I’ve found the Setup relatively useful on my project , From a UX perspective having a fast responding page is really important , So Why not give it a try? ……