You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/content/docs/adapters/svelte-kit.md
+59-1Lines changed: 59 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ description: Use oRPC inside an Svelte Kit project
7
7
8
8
[Svelte Kit](https://svelte.dev/docs/kit/introduction) is a framework for rapidly developing robust, performant web applications using Svelte. For additional context, refer to the [HTTP Adapter](/docs/adapters/http) guide.
9
9
10
-
## Basic
10
+
## Server
11
11
12
12
::: code-group
13
13
@@ -38,3 +38,61 @@ export const DELETE = handle
38
38
::: info
39
39
The `handler` can be any supported oRPC handler, such as [RPCHandler](/docs/rpc-handler), [OpenAPIHandler](/docs/openapi/openapi-handler), or another custom handler.
40
40
:::
41
+
42
+
## Optimize SSR
43
+
44
+
To reduce HTTP requests and improve latency during SSR, you can utilize [Svelte's special `fetch`](https://svelte.dev/docs/kit/web-standards#Fetch-APIs) during SSR. Below is a quick setup, see [Optimize SSR](/docs/best-practices/optimize-ssr) for more details.
45
+
46
+
::: code-group
47
+
48
+
```ts [src/lib/orpc.ts]
49
+
importtype { RouterClient } from'@orpc/server'
50
+
import { RPCLink } from'@orpc/client/fetch'
51
+
import { createORPCClient } from'@orpc/client'
52
+
53
+
declareglobal {
54
+
var $client:RouterClient<typeofrouter> |undefined
55
+
}
56
+
57
+
const link =newRPCLink({
58
+
url: () => {
59
+
if (typeofwindow==='undefined') {
60
+
thrownewError('This link is not allowed on the server side.')
0 commit comments