Traditional server-side rendering (SSR) is blocked until the slowest database query or 3rd party API call completes. GoKS solves this withStreaming SSRandcomponent.Suspense.
How Streaming Works in GoKS
- The server sends the primary HTML shell and loading skeleton fallbacks immediately overchunked HTTP transfer encoding.
- Slow asynchronous blocks execute in parallel in independent Go goroutines.
- When each goroutine finishes, GoKS streams the resolved HTML chunk along with a zero-dependency inline
<template>script that replaces the skeleton DOM node in place.
Suspense Component Example
app/dashboard/page.gox
package dashboard
import (
"time"
"github.com/misbakhul29/goks/pkg/component"
"github.com/misbakhul29/goks/pkg/html"
)
type Page struct {
component.ComponentBase
}
func (p *Page) Render() *component.Node {
return html.Div(html.H1("User Analytics").Class("text-3xl font-bold text-white mb-6"), "{component.Suspense(\n\t\t\t\t&component.SuspenseConfig{\n\t\t\t\t\tFallback: (", html.Div("Loading real-time revenue metrics...").Class("p-6 rounded-xl bg-slate-900 animate-pulse text-slate-500"), "),\n\t\t\t\t\tContent: func() *component.Node {\n\t\t\t\t\t\ttime.Sleep(500 * time.Millisecond) // Simulated DB latency\n\t\t\t\t\t\treturn (", html.Div("Monthly Revenue: $128,400.00 (+14.2%)").Class("p-6 rounded-xl bg-emerald-950/40 border border-emerald-500/30 text-emerald-300"), ")\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t)}").Class("p-8")
}Key Benefits
- Sub-Millisecond TTFB:The initial document shell flushes to the browser almost instantly.
- Zero Client JS Required:Out-of-order template swapping uses a tiny inline DOM replacement script (under 100 bytes) without requiring WebAssembly or virtual DOM.
- SEO Friendly:Search engine crawlers supporting streaming responses receive the fully resolved document without timeouts.