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

critical-path-check

v1.1.3

Published

A critical path analysis tool powered by rust

Readme

Critical Path Check

A rust powered tool for making assertions on a web application's critical path

  1. Installation
  2. Rust API
  3. JavaScript API
  4. Command Line

Installation

JavaScript/TypeScript

npm i -D critical-path-check
yarn add -D critical-path-check
pnpm add -D critical-path-check

Rust

cargo add critical_path_check

JavaScript API

All methods exposed by the JavaScript API require a path to an HTML file. This path can be

  1. An absolute path to an HTML file locally on your machine
  2. The URL of a remote HTML file - ie - https://github.com

analyzeCriticalPath

Returns a critical path analysis containing the byte-weight of your entrypoint modules including, HTML, CSS, and JavaScript. This method will also return any unresolvable paths encountered during the analysis

import { analyzeCriticalPath } from "critical-path-check";

test("Critical Path should never exceed N bytes", () => {
  const buildPath = path.join(process.cwd(), "dist", "index.html");
  const { htmlWeight, cssWeight, javascriptWeight } =
    analyzeCriticalPath(buildPath);
  expect(htmlWeight).toBeLessThan(51200);
  expect(cssWeight).toBeLessThan(102400);
  expect(javascriptWeight).toBeLessThan(204800);
});

measureCriticalPath

Returns the combined weight of critical HTML, CSS, and JavaScript in bytes

import { measureCriticalPath } from "critical-path-check";

test("The critical path should never exceed N bytes", () => {
  const buildPath = path.join(process.cwd(), "dist", "index.html");
  expect(measureCriticalPath(buildPath)).toBeLessThan(204800);
});

assertCriticalPath

Returns true if the combined weight of critical HTML, CSS, and JS does not exceed the input threshold bytes.

import { assertCriticalPath } from "critical-path-check";

test("Critical Path should never exceed N bytes", () => {
  const buildPath = path.join(process.cwd(), "dist", "index.html");
  expect(assertCriticalPath(buildPath, 204800)).toEqual(true);
});

assertCriticalHTML

Returns true if the weight of critical HTML does not exceed the input threshold bytes.

import { assertCriticalHTML } from "critical-path-check";

test("Critical HTML should never exceed N bytes", () => {
  const buildPath = path.join(process.cwd(), "dist", "index.html");
  expect(assertCriticalHTML(buildPath, 51200)).toEqual(true);
});

assertCriticalCSS

Returns true if the weight of critical CSS does not exceed the input threshold bytes.

import { assertCriticalCSS } from "critical-path-check";

test("Critical CSS should never exceed N bytes", () => {
  const buildPath = path.join(process.cwd(), "dist", "index.html");
  expect(assertCriticalCSS(buildPath, 102400)).toEqual(true);
});

assertCriticalJavaScript

Returns true if the combined weight of critical JS does not exceed the input threshold bytes.

import { assertCriticalJavaScript } from "critical-path-check";

test("Critical JavaScript should never exceed N bytes", () => {
  const buildPath = path.join(process.cwd(), "dist", "index.html");
  expect(assertCriticalJavaScript(buildPath, 204800)).toEqual(true);
});

Rust API

analyze_critical_path

Analyzes the target HTML file's critical render path

Returns the critical weight (in bytes) required to render your page. It also returns any unresolvable paths that were encountered during the analysis

use critical_path_check::analyze_critical_path;

let my_html = PathBuf::from("/path/to/my/root.html");
let result = analyze_critical_path(&my_html);

println!("Total JS Bytes: {}", result.analysis.javascript_weight);
println!("Total CSS Bytes: {}", result.analysis.css_weight);
println!("Total HTML Bytes: {}", result.analysis.html_weight);

CriticalPathCheck

The underlying struct and impl powering the critical path check.

There are three ways to spawn instances of the CriticalPathCheck

use critical_path_check::critical_path_check::CriticalPathCheck;

/// using a string representing an absolute path to an HTML file
let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
/// or using a URL to a remotely hosted build
let cp_check = CriticalPathCheck::new("https://my-app.com");
/// or using a PathBuf
let cp_check = CriticalPathCheck::from(PathBuf::from("/path/to/my/root.html"));

CriticalPathCheck.run(&self): CriticalPathAnalysis

Returns a critical path analysis containing the byte-weights of critical HTML, CSS, and JavaScript as well as any unresolvable imports/references encountered

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
let result = cp_check.run();

CriticalPathCheck.measure(&self): usize

Returns the combined weight of critical HTML, CSS, and JavaScript

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
let total_bytes = cp_check.measure();

CriticalPathCheck.assert(&self, bytes: usize): bool

Returns true if the specified number of bytes is greater than the cummulative critical path

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
let check_passed = cp_check.assert(1000000);

CriticalPathCheck.assert_html(&self, bytes: usize): bool

Returns true if the specified number of bytes is greater than the byte-weight of the critical HTML

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
let check_passed = cp_check.assert_html(50000);

CriticalPathCheck.assert_css(&self, bytes: usize): bool

Returns true if the specified number of bytes is greater than the byte-weight of the critical CSS

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
let check_passed = cp_check.assert_css(100000);

CriticalPathCheck.assert_javascript(&self, bytes: usize): bool

Returns true if the specified number of bytes is greater than the byte-weight of the critical JavaScript

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
let check_passed = cp_check.assert_javascript(500000);

CriticalPathCheck.run_cli(&self)

Executes the critical path analysis as a CLI command logging all results to stdout

use critical_path_check::critical_path_check::CriticalPathCheck;

let cp_check = CriticalPathCheck::new("/path/to/my/root.html");
cp_check.run_cli();

Command Line

The critical path check can be used as a CLI simply by installing the crate and running

critical-path-check /absolute/path/or/url/to/your-app.html