Install using bunx shadcn@latest add @remix-utils/middleware-server-timing.
bunx shadcn@latest add @remix-utils/middleware-server-timing
This depends on @edgefirst-dev/server-timing.
@edgefirst-dev/server-timing
The server timing middleware let's you add a Server-Timing header to the response with the time it took to run the loaders and actions.
Server-Timing
import { createServerTimingMiddleware } from "remix-utils/middleware/server-timing";export const [serverTimingMiddleware, getTimingCollector] = createServerTimingMiddleware(); Copy
import { createServerTimingMiddleware } from "remix-utils/middleware/server-timing";export const [serverTimingMiddleware, getTimingCollector] = createServerTimingMiddleware();
To use it, you need to add it to the middleware array in your app/root.tsx file.
middleware
app/root.tsx
import { serverTimingMiddleware } from "~/middleware/server-timing.server";export const middleware: Route.MiddlewareFunction[] = [serverTimingMiddleware]; Copy
import { serverTimingMiddleware } from "~/middleware/server-timing.server";export const middleware: Route.MiddlewareFunction[] = [serverTimingMiddleware];
And you can use the getTimingCollector function in your loaders and actions to add timings to the response.
getTimingCollector
import { getTimingCollector } from "~/middleware/server-timing.server";export async function loader({ request }: Route.LoaderArgs) { let collector = getTimingCollector(); return await collector.measure("name", "optional description", async () => { return await getData(); });} Copy
import { getTimingCollector } from "~/middleware/server-timing.server";export async function loader({ request }: Route.LoaderArgs) { let collector = getTimingCollector(); return await collector.measure("name", "optional description", async () => { return await getData(); });}
The measure function will measure the time it took to run the function passed as the last argument and add it to the Server-Timing header.
measure
Sergio XalambrÃ
Install using
bunx shadcn@latest add @remix-utils/middleware-server-timing.This depends on
@edgefirst-dev/server-timing.The server timing middleware let's you add a
Server-Timingheader to the response with the time it took to run the loaders and actions.To use it, you need to add it to the
middlewarearray in yourapp/root.tsxfile.And you can use the
getTimingCollectorfunction in your loaders and actions to add timings to the response.The
measurefunction will measure the time it took to run the function passed as the last argument and add it to theServer-Timingheader.Author
Sergio XalambrÃ