Condense is a high-performance, stateless file optimization and minification engine for Node.js. It optimizes images, audio, video, and code entirely in-memory using Buffers and Streams, and avoids writing temporary files to disk.
Condense provides fast, in-memory optimization for media and code. It exists to offer low-latency, stateless processing for server-side and serverless environments where temporary disk I/O is undesirable or unavailable. Unlike traditional tools that rely on intermediate temporary files, Condense processes uploads and assets using Buffers and Streams, returning optimized Buffers or Streams ready to send in responses.
- Why Condense?
- Features
- Supported Formats
- Installation
- Quick Start
- Usage
- Ignore Directives
- API Reference
- Architecture Diagram
- Benchmarks
- System Requirements
- License
- No temporary files: Processes files entirely in-memory using Buffers and Streams without writing temporary files to disk.
- Stateless architecture: Optimizations are performed per-request without persistent state, easing horizontal scaling.
- API-friendly: Designed to integrate cleanly into HTTP APIs and microservices.
- Serverless-ready: Works well in ephemeral environments (Cloud Functions, Lambda-like runtimes) where disk access is limited.
- High-throughput: Efficient pipelines suitable for high-volume media processing.
- Low-latency: Optimized for minimal added latency in request/response flows.
- In-memory Buffer & Stream processing (no temporary disk writes)
- Image, audio, video, and code/markup optimization
- Express middleware and standalone CLI options
- Ignore directives to opt-out specific regions or files from minification
| Category | Formats |
|---|---|
| Images | PNG, JPG, JPEG, WebP |
| Audio | MP3, WAV |
| Video | MP4 |
| Code & Markup | HTML, CSS, JavaScript, JSON |
Install with your preferred package manager:
npm i @studioframes/condenseyarn add @studioframes/condensepnpm add @studioframes/condensebun add @studioframes/condenseThe simplest in-process example — optimize an image Buffer and get back an optimized Buffer:
const { optimizeImage } = require('@studioframes/condense');
async function simpleOptimize(rawBuffer) {
const { buffer: optimized, outMime } = await optimizeImage(rawBuffer, 'image/png', 'quality');
// send `optimized` as the HTTP response body with Content-Type `outMime`
return { optimized, outMime };
}
// Usage: pass a Buffer (e.g., from file upload or fetch response)Condense can run as a standalone CLI server, be mounted as Express middleware, or be used programmatically.
- CLI:
npx @studioframes/condense(defaults to port 3000; setPORTto override) - Express: mount
condenseAppon a route to accept uploads - Programmatic: use helpers such as
optimizeImage,optimizeText,optimizeMediaStream
const express = require('express');
const { condenseApp } = require('@studioframes/condense');
const app = express();
// Mount all optimization routes under a specific path
app.use('/v1', condenseApp);
app.listen(8080, () => {
console.log('App running. POST files to http://localhost:8080/v1/optimize');
});const { optimizeImage, optimizeText, optimizeMediaStream } = require('@studioframes/condense');
// 1. Optimize an Image Buffer (returns Buffer)
const { buffer: imgBuffer, outMime: imgMime } = await optimizeImage(rawImageBuffer, 'image/png', 'extreme');
// 2. Optimize an HTML / CSS / JS Buffer (returns Buffer)
const { buffer: textBuffer, outMime: textMime } = await optimizeText(rawHtmlBuffer, 'text/html', 'quality');
// 3. Optimize Audio / Video (returns PassThrough Stream)
const { stream, outMime: mediaMime } = optimizeMediaStream(rawVideoBuffer, 'video/mp4', 'quality');Use ignore directives to prevent minification for a file or a specific region.
- HTML: add
data-condense-ignoreto any element (or<html>to ignore the whole document). - JS/CSS: add the comment
/* condense-ignore */anywhere in the file to bypass minification.
Example (HTML):
<div data-condense-ignore>
<pre>
Preserved spacing and content here
</pre>
</div>Example (JS):
/* condense-ignore */
function legacyCode() {
// This file will not be altered
var x = 10;
}Example (CSS):
/* condense-ignore */
p {
color: red;
text-align: center;
}POST /optimize
- Multipart form:
file(binary),method(quality|extreme) - Returns optimized binary in the response body with appropriate
Content-Type.
curl -X POST http://localhost:3000/v1/optimize \
-F "file=@./photo.png" \
-F "method=extreme" \
--output photo-condensed.webpClient Upload
↓
Buffer
↓
Condense
↓
Buffer/Stream
↓
Response
Short explanation: uploads are received into memory (Buffers or Streams), processed by Condense in-memory, and returned as an optimized Buffer or Stream without intermediate disk writes.
| File Type | Original Size | Optimized Size |
|---|---|---|
| PNG | 4.2 MB | 1.1 MB |
| MP4 | 25 MB | 9 MB |
| HTML | 120 KB | 42 KB |
*These numbers are illustrative. Actual savings vary depending on content, encoding, and chosen optimization method.
- Minimum Node.js: >= 20.9
- Uses native binaries (
sharp,ffmpeg-static) where applicable
This project is managed by Studio Frames and is licensed under the Apache License 2.0. See https://github.com/studioframes/Condense/blob/main/LICENSE for the full text.
