Registry / http-networking / shrink-ray-current

shrink-ray-current

JSON →
library4.1.3jsnpmunverified

Shrink-ray-current is a Node.js compression middleware designed for Express/Connect applications, providing advanced content encoding capabilities beyond standard gzip. Currently stable at version 4.1.3 (last updated April 2021), it's a maintained fork of the abandoned `shrink-ray` package, ensuring its dependencies are up-to-date. Its key differentiators include built-in support for Brotli and Zopfli (the latter specifically for asynchronous compression of static assets), alongside traditional deflate and gzip. The middleware leverages ETag caching to significantly boost performance for static files, claiming to be 3x faster and using a quarter of the CPU time compared to the standard `compression` middleware in benchmarks, by utilizing higher quality compression algorithms for cached content. Releases appear to be driven by dependency updates or minor bug fixes rather than a fixed schedule.

npm install shrink-ray-current
INSTALL
IMPORT
SIG · SHRINK-RAY-CURRENT
S
shrink-ray-current
http-networkingjavascriptv4.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

shrinkRay
const shrinkRay = require('shrink-ray-current');
const shrinkRay = require('shrink-ray');
CommonJS import for Node.js applications. Ensure you are importing from `shrink-ray-current` and not the abandoned `shrink-ray`.
shrinkRay
import shrinkRay from 'shrink-ray-current';
import { shrinkRay } from 'shrink-ray-current';
ESM import. The middleware function is typically exported as the default.
Options
import type { Options } from 'shrink-ray-current';
TypeScript type import for configuring the middleware options.

Demonstrates integrating `shrink-ray-current` as Express/Connect middleware for both dynamic and (simulated) static content, showing basic setup and enabling compression for routes.

const express = require('express'); const shrinkRay = require('shrink-ray-current'); const app = express(); // Use the middleware with default options app.use(shrinkRay()); // Example route for dynamic content app.get('/', (req, res) => { res.send('Hello World! This content will be compressed.'); }); // Example route for static-like content (e.g., a large JSON file) app.get('/data', (req, res) => { const largeData = Array(1000).fill({ id: Math.random(), name: 'Item ' + Math.random(), description: 'This is a long description for a test item to ensure compression benefits are visible.', details: { field1: 'value1', field2: 'value2', field3: 'value3', nested: { a: 1, b: 2, c: 3 } } }); res.json(largeData); }); // Start the server const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`Server listening on port ${port}`); console.log('Try accessing / and /data with accept-encoding headers (e.g., curl -H "Accept-Encoding: gzip, deflate, br" http://localhost:3000/data).'); });
Debug
Known issues
breakingAs of v4.0.0, `iltorb` (Brotli) and `node-zopfli-es` (Zopfli) are now peer dependencies. They are no longer installed automatically.
fix
Manually install these packages as optional dependencies in your project: `npm install --save-optional iltorb node-zopfli-es`.
affects: >=4.0.0
gotchaThe package `shrink-ray-current` is a maintained fork of the original `shrink-ray`, which is abandoned. Ensure you install and import the correct package.
fix
Always use `npm install shrink-ray-current` and `require('shrink-ray-current')` or `import 'shrink-ray-current'`. Do not use `shrink-ray`.
affects: >=1.0.0
gotchaNative module dependencies (`iltorb` and `node-zopfli-es`) require a Node.js native build toolchain (e.g., node-gyp, Python, C++ compiler) to install successfully. If these fail to build, `shrink-ray-current` will fall back to using only gzip/deflate.
fix
Install the necessary build tools as per Node.js documentation for your operating system, or ensure your deployment environment supports native module compilation. For example, on Ubuntu: `sudo apt-get install python make g++`.
affects: >=1.0.0
gotchaZopfli compression is specifically noted for asynchronous compression of *static assets only* (e.g., content with ETags). It is not applied to all outgoing responses by default.
fix
Be aware of Zopfli's specific use case. If you need maximum compression for static assets, ensure ETags are enabled for those responses. For general dynamic content, Brotli/gzip will be used based on client `Accept-Encoding`.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'iltorb' (or 'node-zopfli-es')
The peer dependencies for Brotli and Zopfli compression were not installed after `shrink-ray-current` v4.0.0.
fix
Install the missing optional dependencies: `npm install --save-optional iltorb node-zopfli-es`.
node-gyp rebuild failed
Native modules (iltorb, node-zopfli-es) failed to compile during installation, typically due to missing system-level build tools.
fix
Ensure you have the Node.js native build toolchain installed. This usually includes Python, Make, and a C++ compiler (e.g., Visual Studio Build Tools on Windows, Xcode Command Line Tools on macOS, or `build-essential` on Debian/Ubuntu).
Upgrade
Version history
4.1.3latest on npm
Audit
Dependencies
iltorboptionalProvides Brotli compression support.
node-zopfli-esoptionalProvides Zopfli compression support.
Agent activity
15 hits · last 30 days
node
8
OpenAI (training)
1
Resources
shrink-ray-current — npm install shrink-ray-current · libregistry