Skip to content

Server Timing

Bun

Start by installing @bit-js/web-utils:

Terminal window
bun add @bit-js/web-utils

Use it like so:

import { serverTiming } from '@bit-js/web-utils';
// Set the resolve time
app.set('resolveTime', serverTiming.metric('resolveTime'));
// Set the result later
app.defer((res, ctx) => {
if(!(res instanceof Response)) return ctx.end();
ctx.resolveTime.append(res.headers);
});
// Do route handling normally
app.post('/new', (ctx) => {
// Do something
resolveSomething(ctx);
});

Deno

Use it like so:

import { serverTiming } from 'npm:@bit-js/web-utils';
// Set the resolve time
app.set('resolveTime', serverTiming.metric('resolveTime'));
// Set the result later
app.defer((res, ctx) => {
if(!(res instanceof Response)) return ctx.end();
ctx.resolveTime.append(res.headers);
});
// Do route handling normally
app.post('/new', (ctx) => {
// Do something
resolveSomething(ctx);
});

To specify a description for the metric:

serverTiming.metric('db_query', 'The time taken to finish a database query');