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

xypriss-compression-pluging

v1.0.3

Published

Custom compression middleware for XyPriss with strict algorithm enforcement

Readme

XyPriss Compression

Custom compression middleware for Express/Connect with strict algorithm enforcement.

Key Feature

Unlike the standard compression package, xypriss-compression enforces which compression algorithms can be used. If you configure algorithms: ['br', 'deflate'], it will never use gzip, even if the client requests it.

Problem Solved

The original compression package has no way to restrict which algorithms are used. It automatically chooses based on the client's Accept-Encoding header, ignoring your configuration.

Example of the problem:

// Using standard 'compression' package
const compression = require("compression");
app.use(
  compression({
    // This option doesn't exist!
    // algorithms: ['br', 'deflate']
  })
);

// Client requests gzip → Server uses gzip (no control!)

With xypriss-compression:

import compression from "xypriss-compression-pluging";

app.use(
  compression({
    algorithms: ["br", "deflate"], // STRICTLY ENFORCED
  })
);

// Client requests gzip → Server responds with identity (uncompressed)
// Client requests br → Server uses brotli
// Client requests deflate → Server uses deflate

Installation

npm install xypriss-compression

Usage

Basic Usage

import express from "express";
import compression from "xypriss-compression-pluging";

const app = express();

// Use with default settings (gzip, deflate)
app.use(compression());

app.listen(3000);

With Algorithm Enforcement

import compression from "xypriss-compression-pluging";

app.use(
  compression({
    // Only allow Brotli and Deflate
    algorithms: ["br", "deflate"],

    // Compression level (1-9 for gzip/deflate, 0-11 for brotli)
    level: 6,

    // Minimum size to compress (1KB)
    threshold: "1kb",
  })
);

Advanced Configuration

app.use(
  compression({
    algorithms: ["br", "gzip"],
    level: 9,
    threshold: 2048,

    // Custom filter
    filter: (req, res) => {
      // Don't compress images
      const type = res.getHeader("Content-Type");
      if (type && type.toString().startsWith("image/")) {
        return false;
      }
      return true;
    },

    // Brotli-specific options
    brotli: {
      params: {
        [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
      },
    },

    // Gzip-specific options
    gzip: {
      memLevel: 8,
    },
  })
);

API

compression(options?)

Creates a compression middleware.

Options

| Option | Type | Default | Description | | ------------ | ------------------------------------ | --------------------- | --------------------------------------------------------- | | algorithms | Array<'gzip' \| 'deflate' \| 'br'> | ['gzip', 'deflate'] | Strictly enforced list of allowed algorithms | | level | number | 6 | Compression level (1-9 for gzip/deflate, 0-11 for brotli) | | threshold | number \| string | 1024 | Minimum response size to compress | | filter | Function | shouldCompress | Custom filter function | | brotli | BrotliOptions | {} | Brotli-specific options | | gzip | ZlibOptions | {} | Gzip-specific options | | deflate | ZlibOptions | {} | Deflate-specific options |

How It Works

  1. Client sends request with Accept-Encoding: gzip, deflate, br
  2. Middleware checks which algorithms are in the algorithms config
  3. Selects best match from allowed algorithms (priority: br > gzip > deflate)
  4. If no match, responds with uncompressed data (identity)

Algorithm Selection Priority

When multiple algorithms are allowed and accepted by the client:

  1. Brotli (br) - Best compression ratio
  2. Gzip (gzip) - Good compression, widely supported
  3. Deflate (deflate) - Faster but less efficient

Comparison with compression

| Feature | compression | xypriss-compression | | --------------------- | ------------- | --------------------- | | Algorithm enforcement | No | Yes | | TypeScript | No | Yes | | Custom filters | Yes | Yes | | Threshold | Yes | Yes | | Brotli support | Yes | Yes |

Use Cases

Security Compliance

// Only use approved algorithms
app.use(
  compression({
    algorithms: ["br"], // Company policy: Brotli only
  })
);

Performance Optimization

// Prefer speed over compression ratio
app.use(
  compression({
    algorithms: ["deflate"], // Fastest
    level: 1,
  })
);

Modern Browsers Only

// Serve Brotli to modern browsers, nothing to old ones
app.use(
  compression({
    algorithms: ["br"],
    filter: (req, res) => {
      // Fallback to uncompressed for old browsers
      return req.headers["user-agent"]?.includes("Chrome") || false;
    },
  })
);

Debugging

Enable debug logs:

DEBUG=xypriss:compression node app.js

License

MIT

Author

Nehonix Team

Credits

Based on expressjs/compression but with strict algorithm enforcement.

Links