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 🙏

© 2025 – Pkg Stats / Ryan Hefner

http-vary

v1.0.3

Published

A minimal parser and utility for the HTTP Vary header.

Downloads

1,228

Readme

Issues Stars License Codecov FOSSA Status Join the chat at https://gitter.im/tinylibs-js-org/community Speed Blazing

Latest Version Downloads JsDelivr Bundlephobia Packagephobia

Table of Contents

Installing

Node

npm install http-vary # or yarn add http-vary
const { parse, compare } = require('http-vary');
import { parse, compare } from 'http-vary';

Browser

<script
  crossorigin
  src="https://cdn.jsdelivr.net/npm/http-vary@latest/dist/index.umd.js"
></script>
const { parse, compare } = window.httpVary;

Url Import

import { parse, compare } from 'https://cdn.skypack.dev/http-vary@latest';

Getting Started

This package is a parser and utility for the HTTP Vary header as defined in RFC 9110 Section 12.5.5. The Vary header indicates which request headers affect the response, enabling proper HTTP caching behavior. You can parse a Vary header string with parse() and compare request headers for cache equivalence with compare().

All needed documentation is available in form of TSDoc comments.

Usage

import { parse, compare, VaryHeader } from 'http-vary';

// Parse a Vary header
const rawHeader = 'Accept-Encoding, User-Agent';

const vary = parse(rawHeader);
// => ['accept-encoding', 'user-agent']

// Parse wildcard
const wildcardVary = parse('*');
// => '*'

// Compare headers for cache equivalence
const headers1 = {
  'Accept-Encoding': 'gzip',
  'User-Agent': 'Chrome'
};

const headers2 = {
  'Accept-Encoding': 'gzip',
  'User-Agent': 'Chrome',
  Cookie: 'session=abc' // This header is ignored
};

const isEquivalent = compare(vary, headers1, headers2);
// => true (headers match for the fields specified in Vary)

// Case-insensitive header matching (per RFC 9110)
const headers3 = {
  'accept-encoding': 'gzip', // lowercase
  'USER-AGENT': 'Chrome' // uppercase
};

const caseInsensitiveMatch = compare(vary, headers1, headers3);
// => true (header names are matched case-insensitively)

// Wildcard always returns false
const wildcardMatch = compare('*', headers1, headers2);
// => false (wildcard indicates response varies on aspects beyond headers)

Understanding Wildcard Behavior

Per RFC 9110, Vary: * signals that the response can vary based on anything about the request, including factors beyond headers (e.g., client IP, time, server load, A/B testing). Since we cannot determine if two requests would receive the same response, compare() always returns false for wildcard, preventing incorrect cache hits.

TL;DR: Vary: * means "don't cache" - always consult the origin server.

License

Licensed under the MIT. See LICENSE for more informations.

FOSSA Status