This depends on @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.
@edgefirst-dev/server-timing
Server-Timing
import { unstable_createServerTimingMiddleware } from "remix-utils/middleware/server-timing";export const [serverTimingMiddleware, getTimingCollector] = unstable_createServerTimingMiddleware(); Copy
import { unstable_createServerTimingMiddleware } from "remix-utils/middleware/server-timing";export const [serverTimingMiddleware, getTimingCollector] = unstable_createServerTimingMiddleware();
To use it, you need to add it to the unstable_middleware array in your app/root.tsx file.
unstable_middleware
app/root.tsx
import { serverTimingMiddleware } from "~/middleware/server-timing.server";export const unstable_middleware = [serverTimingMiddleware]; Copy
import { serverTimingMiddleware } from "~/middleware/server-timing.server";export const unstable_middleware = [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 }: LoaderFunctionArgs) { 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 }: LoaderFunctionArgs) { 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Ã
To use it, you need to add it to the
unstable_middleware
array in yourapp/root.tsx
file.And you can use the
getTimingCollector
function in your loaders and actions to add timings to the response.The
measure
function will measure the time it took to run the function passed as the last argument and add it to theServer-Timing
header.Author
Sergio XalambrÃ