Skip to main content
@cloudflare/speedtest is the JavaScript SDK that powers speed.cloudflare.com. Embed it in any web application to measure your users’ real connection quality with a single import.

Quick Start

Get a working speed test running in minutes

Configuration

Customize measurements, APIs, and thresholds

Results API

Access bandwidth, latency, jitter, and packet loss data

AIM Scores

Network quality scores for streaming, gaming, and video calls

Packet Loss

Measure UDP packet loss via WebRTC TURN

API Reference

Full class and method reference

How it works

The SDK performs a sequence of HTTP requests against Cloudflare’s edge network and uses the browser’s PerformanceResourceTiming API to extract precise timing data. It characterizes your connection across five dimensions:
  • Download bandwidth — measured by fetching files of increasing sizes
  • Upload bandwidth — measured by posting payloads of increasing sizes
  • Latency — round-trip time at idle (unloaded) and under load
  • Jitter — variability in consecutive latency measurements
  • Packet loss — UDP packet loss ratio via a WebRTC TURN server
1

Install the package

npm install @cloudflare/speedtest
2

Import and run

import SpeedTest from '@cloudflare/speedtest';

new SpeedTest().onFinish = results => console.log(results.getSummary());
3

Read the results

The onFinish callback receives a Results object with methods for every metric: getDownloadBandwidth(), getUploadBandwidth(), getUnloadedLatency(), getPacketLoss(), getScores(), and more.
Measurement results are collected by Cloudflare on completion for the purpose of calculating aggregated Internet quality insights.

Build docs developers (and LLMs) love