Skip to main content
NetScriptdocs Search docs ⌘K v0.0.9
Browse documentation

Web layer

This page maps the web-layer guides. The web layer is @netscript/fresh, a server-first meta-framework built on Fresh 2.x and Preact. Its pages load data through the same contract object your services implement, so when a contract changes, the page that depends on it fails deno check instead of failing in production.

In a scaffolded workspace, apps/dashboard/lib/example-service.ts imports UsersContractV1 and derives a typed client and TanStack Query factories from it. The users service implements the same contract. Reshape an endpoint and every page loader, island and form that consumes it becomes a compile error with a file and line number.

How a page is put together

You author a page with definePage(). It binds a typed route contract, server resources, layers (each with its own loader, cache window and partial-refresh endpoint) and forms, then builds them into Fresh route wiring. Handlers run in Deno and return HTML. Only components under islands/ ship JavaScript to the browser, where they hydrate against the same query cache the server dehydrated.

client | server: contract boundary
island hydrates in browser
Browser
(island)
Fresh route
(definePage)
Server handler
(loader)
SDK client
(typed client)
oRPC service
Database
(Prisma)
The Fresh page model: definePage binds a route, runs server loaders through the typed SDK to a service, renders HTML, and hydrates islands against a shared query cache. One contract runs end to end.

Guides

Each guide covers one part of that model. Read the one you need.

  • Fresh page model: server-first rendering, the islands boundary, and defineFreshApp() from @netscript/fresh/server, the bootstrap every NetScript Fresh app starts from.
  • The define-page builder: definePage() and definePartial() from @netscript/fresh/builders, with typed layers, defer policies and per-layer partial refresh.
  • Request-scoped resources: withResource(), one value resolved once per request and shared by every layer, layout and metadata resolver on the page.
  • Layers, layout, and slots: withLayer() and withLayout(), named regions that resolve concurrently, each with its own loader, fallback and freshness window.
  • Response shaping: withMeta(), withHeader(), withStatus(), and the GET handler build() synthesises from them.
  • Route contracts: defineRouteContract(), schema helpers such as paginationSearchSchema() and defineEnumPathParam(), and the generated routes tree that turns a moved route file into a compile error.
  • Generated web surface: which files in a Fresh app you own and which the route generator rewrites.
  • Partials: definePartial(), paired route references, and the layer config that turns a region into a cache-aware deferred partial.
  • Deferred & streaming UI: stream a fallback now and swap in real content when a slower layer resolves.
  • Data loading & the query cache: QueryIsland, useQuery, useMutation and useLiveQuery, the TanStack Query bridge that shares one cache between server render and island hydration.
  • Query bridge: SDK query factories from loader to island, the two key tiers, getCachedEntry() as a read rather than a fetch, and when to dehydrate instead of passing initialData.
  • Server-validated forms: typed, contract-aware form handling declared as a page layer.
  • Interactivity and durable-stream consumption: island runtime helpers and the browser-side client for durable HTTP/SSE streams.
  • Vite integration, testing and diagnostics. For a worked example of the whole layer, follow the Live Dashboard tutorial.
  • Fresh UI & design: the visual layer on top, with the copy-source component registry, design tokens and the scaffolded dashboard app.

Learn, do, look up

Search all documentation

Type a term to search the documentation.