JSandy Logo

JSandy

docs

GitHubStar on GitHub0

Introduction

  • Key Features

Getting Started

  • First Steps
  • Local Development
  • Environment Variables

Backend

  • AppRouter
  • Routers
  • Procedures
  • API Client
  • Middleware
  • WebSockets
  • Performance
  • Documenting
  • Pub/Sub Adapters

Deploy

  • Vercel
  • Cloudflare Workers
Loading...

No sections on this page.

Performance

JSandy is built on lightweight software such as Hono and Drizzle ORM for high performance out of the box.

To further optimize your app, JSandy allows you to optimize bundle sizes and significantly reduce cold starts through built-in dynamic router and dependency loading.


Dynamically Loading Routers

Dynamically load routers using the dynamic() function to maintain high performance when scaling to many routers. This approach reduces the initial bundle size & improves cold starts:

TypeScript

server/index.ts

import { j } from "./jsandy"
import { dynamic } from "@jsandy/rpc"
 
const api = j
  .router()
  .basePath("/api")
  .use(j.defaults.cors)
  .onError(j.defaults.errorHandler)
 
const appRouter = j.mergeRouters(api, {
  users: dynamic(() => import("./routers/user-router")),
  posts: dynamic(() => import("./routers/post-router")),
})
 
export type AppRouter = typeof appRouter
export default appRouter
import { j } from "./jsandy"
import { dynamic } from "@jsandy/rpc"
 
const api = j
  .router()
  .basePath("/api")
  .use(j.defaults.cors)
  .onError(j.defaults.errorHandler)
 
const appRouter = j.mergeRouters(api, {
  users: dynamic(() => import("./routers/user-router")),
  posts: dynamic(() => import("./routers/post-router")),
})
 
export type AppRouter = typeof appRouter
export default appRouter

Dynamic Imports in Procedures

JSandy also supports dynamic imports within procedures for code splitting at the procedure level. Just like dynamically loading routers, this approach reduces the initial bundle size and can significantly improve cold starts:

TypeScript

server/routers/user-router.ts

import { j, publicProcedure } from "../jsandy"
 
export const userRouter = j.router({
  generateReport: publicProcedure.get(async ({ c }) => {
      // 👇 Dynamically import heavy dependencies
      const { generatePDF } = await import("./utils/pdf-generator")
      const { processData } = await import("./utils/data-processor")
 
      const data = await processData(c.req.query())
      const pdf = await generatePDF(data)
 
      return c.json({ pdf })
    })
})
import { j, publicProcedure } from "../jsandy"
 
export const userRouter = j.router({
  generateReport: publicProcedure.get(async ({ c }) => {
      // 👇 Dynamically import heavy dependencies
      const { generatePDF } = await import("./utils/pdf-generator")
      const { processData } = await import("./utils/data-processor")
 
      const data = await processData(c.req.query())
      const pdf = await generatePDF(data)
 
      return c.json({ pdf })
    })
})
prevWebSocketsnextDocumenting