Skip to content

Repository files navigation

@edgefirst-dev/server-timing

A helper to collect measurements for the Server-Timing header

Usage

Install the package:

bun add @edgefirst-dev/server-timing

Instantiate the timing collector:

import{TimingCollector}from"@edgefirst-dev/server-timing";// You can instantiate this in the getLoadContext of Remix or React Routerletcollector=newTimingCollector();

Take measurements:

collector.measure("my-metrict","optional description",100,async()=>{// do something});

Get the Server-Timing header:

letheaders=newHeaders();collector.toHeaders(headers);

Tip

Use this library in Remix or React Router applications to measure async code like HTTP requests or database queries, then collect the measurements and add them to the Server-Timing header.

Manually collect timings

You can also manually collect timings:

import{Timing}from"@edgefirst-dev/server-timing";// measures are taken from the time this is createdlettiming=newTiming("name","description");awaitdoSomething();// do somethingtiming.end();// end the measurementcollector.add(timing);// add the timing to the collector

Each Timing can be used once. If you want to take different measurements, create a new Timing instance.

Tip

Use the Collector#measure method to automatically create a Timing instance and add it to the collector.

About

A helper to collect measurements for the Server-Timing header

Resources

Contributing

Stars

5 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

Generated from sergiodxa/package