npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@relaxwork/performance-monitor

v1.0.0

Published

A performance monitoring SDK for web applications, providing real-time insights into page load times, resource loading, and user interactions to help developers optimize their web performance.

Readme

Relax Performance Monitor SDK

一个轻量级的前端性能监控 SDK,用于采集页面渲染、用户交互、视觉稳定性以及资源与网络请求相关的性能指标。

相关文档:

功能特性

  • 页面渲染指标: 采集 FPFCPLCPload/pageshow
  • 交互响应指标: 采集 FIDINPLong Task
  • 视觉稳定性指标: 采集 CLS 以及导致偏移的元素信息。
  • 资源加载性能: 采集静态资源加载耗时、协议、大小、TTFB 等数据。
  • 接口请求性能: 采集 fetch / XMLHttpRequest 请求耗时、DNS、TCP、TTFB 等数据。
  • SPA 场景支持: 路由切换时自动结算并上报 CLS。
  • 数据上报: 优先使用 navigator.sendBeacon,不支持时降级为 fetch + keepalive

安装

npm install @relaxwork/performance-monitor

使用方法

import PerformanceMonitor from '@relaxwork/performance-monitor';

const monitor = new PerformanceMonitor({
	reportUrl: 'https://your-monitoring-server.com/api/performance-report',
	log: true,
});

monitor.init();

默认配置:

  • reportUrl: /api/performance
  • log: true

配置项

new PerformanceMonitor(options) 支持以下配置:

| 属性名 | 类型 | 说明 | | --- | --- | --- | | reportUrl | string | 性能数据上报地址 | | log | boolean | 是否输出调试日志,目前主要用于 CLS 调试 |

采集指标说明

1. 页面加载与渲染

| 指标 | 说明 | | --- | --- | | FP | First Paint,首次绘制时间 | | FCP | First Contentful Paint,首次内容绘制时间 | | LCP | Largest Contentful Paint,最大内容绘制时间 | | load | 页面加载完成相关事件耗时 |

LCP 上报时会额外包含:

  • lcpTime
  • elementSelector
  • pageUrl

2. 交互响应

| 指标 | 说明 | | --- | --- | | FID | First Input Delay,首次输入延迟 | | INP | Interaction to Next Paint,交互到下一次绘制的延迟 | | Long Task | 长任务耗时,帮助定位主线程阻塞 |

INP 上报时会包含:

  • inputDelay
  • processingTime
  • presentationDelay
  • interactionId

Long Task 上报时会包含:

  • duration
  • attribution
  • pageUrl

3. 视觉稳定性

SDK 会监听 layout-shift,累计 CLS 值,并记录触发布局偏移的 DOM 元素选择器。

CLS 上报时会包含:

  • clsValue
  • clsEntries
  • isFinal
  • pageUrl

在以下时机会触发最终 CLS 上报:

  • 页面隐藏
  • 页面关闭
  • SPA 路由切换

4. 资源与网络

静态资源性能

SDK 会采集除 fetch / XMLHttpRequest / 上报接口自身 / beacon 之外的资源加载性能,包括:

  • duration
  • dns
  • tcp
  • redirect
  • ttfb
  • protocol
  • transferSize
  • resourceSize

接口请求性能

SDK 会采集 fetchXMLHttpRequest 的请求性能,包括:

  • duration
  • dns
  • tcp
  • ttfb
  • transferSize
  • pageUrl

上报数据示例

LCP:

{
	"type": "performance",
	"name": "largest-contentful-paint",
	"pageUrl": "http://localhost:3000/test/index.html",
	"lcpTime": 1240.5,
	"elementSelector": "img.hero-banner",
	"startTime": 1240.5
}

INP:

{
	"type": "performance",
	"subType": "interaction",
	"name": "click",
	"duration": 86.4,
	"inputDelay": 22.1,
	"processingTime": 30.2,
	"presentationDelay": 34.1,
	"interactionId": 1234,
	"pageUrl": "http://localhost:3000/test/index.html"
}

资源请求:

{
	"name": "http://localhost:3000/api/delay/300",
	"type": "performance",
	"subType": "resource",
	"sourceType": "fetch",
	"duration": 315.7,
	"dns": 0.4,
	"tcp": 1.2,
	"ttfb": 302.5,
	"transferSize": 540,
	"pageUrl": "http://localhost:3000/test/index.html"
}

本地开发

  1. 安装依赖
pnpm install
  1. 构建性能监控 SDK
pnpm --filter @relaxwork/performance-monitor build
  1. 启动本地测试服务
pnpm --filter @relaxwork/performance-monitor demo
  1. 在浏览器中打开 http://localhost:3000/test/index.html

测试页位于 packages/performance/test/index.html,可手动触发:

  • 交互事件
  • 长任务
  • 网络请求
  • CLS 布局偏移
  • SPA 路由切换

License

MIT