Socket
Book a DemoInstallSign in
Socket

@edgefirst-dev/server-timing

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edgefirst-dev/server-timing

A helper to collect measurements for the Server-Timing header

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
602
-34.92%
Maintainers
1
Weekly downloads
 
Created
Source

@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 Router
let collector = new TimingCollector();

Take measurements:

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

Get the Server-Timing header:

let headers = new Headers();
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 created
let timing = new Timing("name", "description");

await doSomething(); // do something

timing.end(); // end the measurement
collector.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.

FAQs

Package last updated on 05 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts