{"id":17120,"library":"shrink-ray-current","title":"shrink-ray-current: Node.js Compression Middleware","description":"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.","status":"active","version":"4.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/Alorel/shrink-ray","tags":["javascript","compression","gzip","deflate","brotli","zopfli","middleware","express","connect"],"install":[{"cmd":"npm install shrink-ray-current","lang":"bash","label":"npm"},{"cmd":"yarn add shrink-ray-current","lang":"bash","label":"yarn"},{"cmd":"pnpm add shrink-ray-current","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides Brotli compression support.","package":"iltorb","optional":true},{"reason":"Provides Zopfli compression support.","package":"node-zopfli-es","optional":true}],"imports":[{"note":"CommonJS import for Node.js applications. Ensure you are importing from `shrink-ray-current` and not the abandoned `shrink-ray`.","wrong":"const shrinkRay = require('shrink-ray');","symbol":"shrinkRay","correct":"const shrinkRay = require('shrink-ray-current');"},{"note":"ESM import. The middleware function is typically exported as the default.","wrong":"import { shrinkRay } from 'shrink-ray-current';","symbol":"shrinkRay","correct":"import shrinkRay from 'shrink-ray-current';"},{"note":"TypeScript type import for configuring the middleware options.","symbol":"Options","correct":"import type { Options } from 'shrink-ray-current';"}],"quickstart":{"code":"const express = require('express');\nconst shrinkRay = require('shrink-ray-current');\n\nconst app = express();\n\n// Use the middleware with default options\napp.use(shrinkRay());\n\n// Example route for dynamic content\napp.get('/', (req, res) => {\n  res.send('Hello World! This content will be compressed.');\n});\n\n// Example route for static-like content (e.g., a large JSON file)\napp.get('/data', (req, res) => {\n  const largeData = Array(1000).fill({\n    id: Math.random(),\n    name: 'Item ' + Math.random(),\n    description: 'This is a long description for a test item to ensure compression benefits are visible.',\n    details: {\n      field1: 'value1',\n      field2: 'value2',\n      field3: 'value3',\n      nested: {\n        a: 1,\n        b: 2,\n        c: 3\n      }\n    }\n  });\n  res.json(largeData);\n});\n\n// Start the server\nconst port = process.env.PORT || 3000;\napp.listen(port, () => {\n  console.log(`Server listening on port ${port}`);\n  console.log('Try accessing / and /data with accept-encoding headers (e.g., curl -H \"Accept-Encoding: gzip, deflate, br\" http://localhost:3000/data).');\n});","lang":"javascript","description":"Demonstrates integrating `shrink-ray-current` as Express/Connect middleware for both dynamic and (simulated) static content, showing basic setup and enabling compression for routes."},"warnings":[{"fix":"Manually install these packages as optional dependencies in your project: `npm install --save-optional iltorb node-zopfli-es`.","message":"As of v4.0.0, `iltorb` (Brotli) and `node-zopfli-es` (Zopfli) are now peer dependencies. They are no longer installed automatically.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Always use `npm install shrink-ray-current` and `require('shrink-ray-current')` or `import 'shrink-ray-current'`. Do not use `shrink-ray`.","message":"The package `shrink-ray-current` is a maintained fork of the original `shrink-ray`, which is abandoned. Ensure you install and import the correct package.","severity":"gotcha","affected_versions":">=1.0.0"},{"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++`.","message":"Native 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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`.","message":"Zopfli 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Install the missing optional dependencies: `npm install --save-optional iltorb node-zopfli-es`.","cause":"The peer dependencies for Brotli and Zopfli compression were not installed after `shrink-ray-current` v4.0.0.","error":"Cannot find module 'iltorb' (or 'node-zopfli-es')"},{"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).","cause":"Native modules (iltorb, node-zopfli-es) failed to compile during installation, typically due to missing system-level build tools.","error":"node-gyp rebuild failed"}],"ecosystem":"npm","meta_description":null}