📄 tanstack/start/latest/docs/framework/solid/guide/static-server-functions

File: static-server-functions.md | Updated: 11/15/2025

Source: https://tanstack.com/start/latest/docs/framework/solid/guide/static-server-functions



TanStack

Start v0v0

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

Solid logo

Solid

Version

Latest

Search...

+ K

Menu

Getting Started

Guides

Examples

Framework

Solid logo

Solid

Version

Latest

Menu

Getting Started

Guides

Examples

On this page

Static Server Functions

Copy Markdown

Warning

Static Server Functions are experimental!

What are Static Server Functions?
---------------------------------

Static server functions are server functions that are executed at build time and cached as static assets when using prerendering/static-generation. They can be set to "static" mode by applying the staticFunctionMiddleware middleware to createServerFn:

tsx

import { createServerFn } from '@tanstack/solid-start'
import { staticFunctionMiddleware } from '@tanstack/start-static-server-functions'

const myServerFn = createServerFn({ method: 'GET' })
  .middleware([staticFunctionMiddleware])
  .handler(async () => {
    return 'Hello, world!'
  })


import { createServerFn } from '@tanstack/solid-start'
import { staticFunctionMiddleware } from '@tanstack/start-static-server-functions'

const myServerFn = createServerFn({ method: 'GET' })
  .middleware([staticFunctionMiddleware])
  .handler(async () => {
    return 'Hello, world!'
  })

Ensure that staticFunctionMiddleware is the final middleware!

This pattern goes as follows:

  • Build-time
    • During build-time prerendering, a server function with staticFunctionMiddleware is executed
    • The result is cached with your build output as a static JSON file under a derived key (function ID + params/payload hash)
    • The result is returned as normal during prerendering/static-generation and used to prerender the page
  • Runtime
    • Initially, the prerendered page's html is served and the server function data is embedded in the html
    • When the client mounts, the embedded server function data is hydrated
    • For future client-side invocations, the server function is replaced with a fetch call to the static JSON file

Edit on GitHub

Server Functions

Environment Functions

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics