← Back to Home

Documentation

Learn how L0ss compresses different file types and what each compression level does.

πŸ”“ L0ss Client - Open Source Edition

Want to compress files without uploading them? Try our 100% client-side version that runs entirely in your browser. All compression happens on your deviceβ€”no uploads, works offline, and is fully open source under MIT license.

πŸ”’
100% Private
Files never leave your device
πŸ“΄
Works Offline
PWA with offline support
⚑
Same Features
All 11 file types supported
πŸš€ Try Client Version ⭐ View on GitHub
πŸ“‹ Quick Navigation

⚑ Quick Reference

Overview of typical compression ranges for each file type.

πŸ“¦ JSON
30-70% reduction
Key compression, null removal, numeric rounding, deduplication
⚑ JavaScript
35-65% reduction
Minification using tdewolff/minify techniques, comment/whitespace removal
🌐 HTML
40-70% reduction
HTML5 optimizations, optional tag removal, attribute minification
🎨 CSS
35-60% reduction
CSSO-inspired optimizations, selector merging, property deduplication
πŸ–ΌοΈ SVG
60-80% reduction
SVGO plugins, path optimization, attribute cleanup, element removal
πŸ“ XML/YAML
10-35% reduction
Whitespace removal, attribute optimization, structure simplification
πŸ“Š CSV
20-50% reduction
Row deduplication, field trimming, numeric rounding
πŸ—„οΈ SQL
25-45% reduction
Comment removal, whitespace optimization, keyword lowercase
πŸ“„ Markdown
10-25% reduction
Link simplification, comment removal, header cleanup, code block optimization
πŸ“ƒ Text
5-15% reduction
Whitespace normalization, line ending cleanup, duplicate line removal

Compression Levels

L0ss offers three compression levels, each with different tradeoffs between file size reduction and data preservation.

Minimal - Safe Optimizations

Recommended for: Production files where accuracy is critical

Typical reduction: 10-30%

Data loss: Low - Removes only redundant data (whitespace, comments, metadata)

Reversibility: Often 100% recoverable to original structure

Moderate - Balanced Approach

Recommended for: Most use cases - best balance of size and quality

Typical reduction: 30-60%

Data loss: Medium - Removes non-critical data and applies smart optimizations

Reversibility: Partially recoverable (core data intact)

Aggressive - Maximum Compression

Recommended for: Testing, prototypes, or when size is paramount

Typical reduction: 60-90%

Data loss: High - Keeps only essential data

Reversibility: Limited (skeleton structure only)

File Type Compression Methods

JSON Files

JSON compression focuses on removing verbosity while maintaining structure.

Minimal Level:

Moderate Level:

Aggressive Level:

Example:

// Original (428 bytes)
{
  "users": [
    {
      "id": 1,
      "name": "John Doe",
      "email": "john@example.com",
      "bio": "Software engineer with 10 years experience...",
      "score": 87.6543,
      "metadata": {
        "created": "2023-01-15",
        "updated": "2024-01-15"
      }
    }
  ]
}

// Moderate (156 bytes, 64% reduction)
{"users":[{"id":1,"name":"John Doe","email":"john@example.com","score":87.65}]}

CSV Files

CSV compression removes unnecessary columns and rows while preserving data structure. Includes advanced techniques for time-series and sequential data.

Minimal Level:

Moderate Level:

// Before (300 bytes)
timestamp,temperature,pressure,humidity
1635724800,20.5,1013.2,65
1635728400,21.2,1013.5,64
1635732000,22.1,1014.1,63
// After with Delta Encoding (320 bytes with metadata)
timestamp(Ξ”),temperature(Ξ”),pressure(Ξ”),humidity(Ξ”)
1635724800,20.5,1013.2,65
+3600.00,+0.70,+0.30,-1.00
+3600.00,+0.90,+0.60,-1.00

Delta Encoding: Inspired by Gorilla time-series database (Facebook) and Daniel Lemire's frame-of-reference encoding. Stores first value as base/reference, then stores deltas (differences) for subsequent values. Example: [100, 105, 110] β†’ [100, +5, +5]. Works best with monotonically increasing values like timestamps, sensor readings, or sequential IDs. Fully reversible via cumulative sum.

References: β€’ "Effective compression using frame-of-reference and delta coding" (Lemire, 2012)
β€’ "The Design of Fast Delta Encoding for Delta Compression Based Storage Systems" (ACM TOS, 2024)
β€’ Wikipedia: Delta Encoding

// Before (480 bytes)
order_id,customer_name,country,product_category,status
1001,Alice Smith,USA,Electronics,Shipped
1002,Bob Johnson,Canada,Clothing,Pending
1003,Carol White,USA,Electronics,Delivered
// After with Dictionary Encoding (240 bytes, 50% reduction)
order_id,customer_name,country(D),product_category(D),status(D)
1001,Alice Smith,0,0,0
1002,Bob Johnson,1,1,1
1003,Carol White,0,0,2

Dictionary Encoding: Inspired by BtrBlocks (SIGMOD 2023) and SAP HANA dictionary compression. Builds a dictionary of unique values and replaces all occurrences with integer codes. Example: ["USA", "Canada", "USA", "Mexico"] β†’ [0, 1, 0, 2] with dictionary {0: "USA", 1: "Canada", 2: "Mexico"}. Works best with categorical data (countries, statuses, types) where unique values are much less than total values. Achieves 10-100x compression on real-world datasets with high repetition. Fully reversible via dictionary lookup.

References: β€’ BtrBlocks: Efficient Columnar Compression for Data Lakes (SIGMOD 2023)
β€’ BtrBlocks on GitHub
β€’ Wikipedia: Dictionary Coder

Aggressive Level:

Note: Aggressive CSV compression can result in significant data loss. These techniques are inspired by database compression algorithms like BtrBlocks (SIGMOD 2023) which achieves 60-80% reduction on real-world datasets. Always test with sample data before using in production.

JavaScript Files

JavaScript compression uses advanced minification techniques inspired by tdewolff/minify, which "employs all the rules that JSMin does too, but has additional improvements."

Minimal Level:

// Before (35 bytes)
function sum(a, b) {
return a + b;
}
// After (27 bytes)
function sum(a,b){return a+b;}

Moderate Level:

// Before (707 bytes)
function calculateTotal(items) {
let total = 0.0;
console.log('calculating...');
if (total === undefined) return 0.5;
return true;
}
// After (360 bytes, 49% reduction)
function calculateTotal(items){let total=0;if (total===void 0)return .5;return !0}

Aggressive Level:

Note: Aggressive optimizations like name mangling can break code that relies on variable names (e.g., for reflection or debugging). Test thoroughly before using in production.

HTML Files

HTML compression uses advanced HTML5 specification techniques inspired by tdewolff/minify.

Minimal Level:

Moderate Level:

Aggressive Level:

Example:

// Before (1032 bytes)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<form>
  <input type="text" required="required">
  <button type="submit">Submit</button>
</form>
<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

// After moderate (562 bytes, 45.5% reduction)
<!DOCTYPE html><form><input required><button>Submit</button></form><ul><li>Item 1<li>Item 2</ul>

CSS Files

CSS compression uses structural optimization techniques inspired by CSSO (CSS Optimizer).

Minimal Level:

Moderate Level:

Aggressive Level:

Example:

// Before (465 bytes)
body {
  margin: 20px 30px;
  margin-left: 0px;
}
h1 { font: 200 36px/1.5 sans-serif; }
h1 { color: #ff6600; }
.button {
  padding: 10px 10px 10px 10px;
  background-color: #ffffff;
}

// After moderate (238 bytes, 48.8% reduction)
body{margin:20px 30px 20px 0}h1{font:200 36px/1.5 sans-serif;color:#f60}.button{padding:10px;background-color:#fff}

SVG Files

SVG compression uses optimization techniques inspired by SVGO (SVG Optimizer) and SVGOMG (Jake Archibald's web GUI for SVGO).

Minimal Level:

<!-- Before (938 bytes) -->
<?xml version="1.0"?>
<!DOCTYPE svg...>
<svg width="800px" height="800px">
<metadata>...</metadata>
<!-- Comment -->
<!-- After (576 bytes, 39% reduction) -->
<svg width="800px" height="800px">...</svg>

Moderate Level:

<!-- Before (2202 bytes) -->
<circle r="0" /><rect width="0" /><g></g>
<rect opacity="1" fill="black" class="" />
<g transform="..."><circle /></g>
<!-- After (457 bytes, 79% reduction) -->
<rect/><circle transform="..."/>

Aggressive Level:

Note: Aggressive path simplification can degrade visual quality. Always compare before/after visuals to ensure acceptable results.

SQL Files

SQL compression uses query optimization techniques inspired by tdewolff/minify to reduce verbosity while maintaining query functionality.

Minimal Level:

-- Before (5120 bytes)
-- Get all users
SELECT *
FROM users
WHERE active = 1;
-- After (3328 bytes, 35% reduction)
SELECT * FROM users WHERE active=1;

Moderate Level:

-- Before (3328 bytes)
SELECT user_table.name FROM user_table LEFT OUTER JOIN orders
INSERT INTO users VALUES (1); INSERT INTO users VALUES (2);
-- After (1670 bytes, 49.8% reduction)
SELECT a.name FROM user_table a LEFT JOIN orders
INSERT INTO users VALUES(1),(2);

Aggressive Level:

-- Before (1670 bytes)
BEGIN;CREATE TABLE users(...);ALTER TABLE...;COMMIT;
INSERT INTO users VALUES(1),(2),(3),(4),(5),(6)...
-- After (494 bytes, 70.4% reduction)
INSERT INTO users VALUES(1),(3),(5)...

Expected Reduction: 35% (minimal), 49.8% (moderate), 70.4% (aggressive) depending on query complexity and data volume.

XML/YAML Files

Structured data compression inspired by tdewolff/minify removes verbosity from markup and configuration files.

XML - Minimal Level:

XML - Moderate Level:

<!-- Before (1585 bytes) -->
<!DOCTYPE html...><![CDATA[text]]><item attr="attr"/>
<!-- After (1039 bytes, 34% reduction) -->
<item attr/>text

YAML - Minimal Level:

YAML - Moderate Level:

# Before (954 bytes)
---
name: "value"
items:
- one
- two
# After (872 bytes, 8.6% reduction)
name:value
items:[one,two]

Expected Reduction: 10-35% depending on markup verbosity and structure complexity.

Markdown Files

Markdown compression removes redundant formatting and simplifies structure while maintaining readability and rendering compatibility.

Minimal Level:

# Before (1344 bytes)
# Heading
Content with trailing spaces
# After (1339 bytes, 0.4% reduction)
# Heading
Content with trailing spaces

Moderate Level:

# Before (1339 bytes)
## Header ##
[Link text][ref]
[ref]: https://example.com
# After (1174 bytes, 12.6% reduction)
## Header
[Link text](https://example.com)

Aggressive Level:

Expected Reduction: 0.4% (minimal), 12.6% (moderate), 20-25% (aggressive) depending on document structure and formatting verbosity.

Plain Text Files

Text file compression focuses on whitespace normalization and duplicate content removal while preserving readability.

Minimal Level:

// Before (2048 bytes)
Line with trailing spaces ␍␊
Another line ␍␊
␊␊␊
// After (1996 bytes, 2.5% reduction)
Line with trailing spaces␊
Another line␊

Moderate Level:

// Before (1996 bytes)
Line one
Duplicate line
Duplicate line
// After (1844 bytes, 7.6% reduction)
Line one
Duplicate line

Aggressive Level:

// Before (1844 bytes)
Indented line
Content line
Other line
Content line
// After (1625 bytes, 11.8% reduction)
Indented line
Content line
Other line

Expected Reduction: 2.5% (minimal), 7.6% (moderate), 11.8% (aggressive) for typical text files with moderate formatting and whitespace.

Research & Techniques

L0ss compression algorithms are inspired by proven open-source projects and academic research in data compression. We stand on the shoulders of giants and give credit where it's due.

JSON Key Compression

Our advanced JSON key compression algorithm uses frequency analysis to assign the shortest codes to the most common keys. This technique can achieve 40-60% additional compression on JSON files with repeated key structures.

Inspired by these projects:

How it works:

  1. Frequency Analysis: Scan entire JSON tree to count how often each key appears
  2. Priority Sorting: Sort keys by frequency (most common first) and length (longest first)
  3. Smart Encoding: Assign single-character codes (0-9, a-z, A-Z) to top 62 keys, then |a, |b, |c... for additional keys
  4. Recursive Application: Apply key mappings throughout the entire object tree

Real-world example:

// Before (1012 bytes)
{
  "users": [
    {
      "firstName": "John",
      "lastName": "Doe",
      "emailAddress": "john@example.com",
      "phoneNumber": "555-1234",
      "streetAddress": "123 Main St",
      "city": "Springfield",
      "state": "IL",
      "postalCode": "62701"
    }
    // ... 2 more users with same structure
  ]
}

// After moderate compression (465 bytes, 54% reduction)
{"e":[{"0":"123 Main St","1":"john@example.com","2":"555-1234","3":"62701","4":"John","5":"Doe","6":"USA","7":"IL","8":"Springfield"},...]}

// Keys compressed: "firstName"β†’"4", "emailAddress"β†’"1", "users"β†’"e"

Multi-Format Minification

Our HTML, CSS, JavaScript, and SVG minification techniques draw from best practices in web optimization.

Inspired by these projects:

Deduplication Techniques

Finding and removing duplicate data blocks is essential for efficient compression.

Inspired by these projects:

Future Research

We're actively exploring additional compression techniques:

Recovery Manifests

Every compression generates a recovery manifest that documents what changes were made. This manifest allows you to understand exactly what was removed or modified.

Manifest Contents:

Using Manifests:

// Download your manifest
GET /api/manifest/:manifestId

// Response includes recovery information
{
  "operations": [
    {"type": "remove_whitespace", "reversible": true},
    {"type": "remove_field", "field": "metadata", "reversible": false},
    {"type": "round_numbers", "precision": 2, "reversible": false}
  ],
  "reversibility": "Partially recoverable"
}

Best Practices

Choosing a Compression Level:

Use Case Recommended Level Reason
Production backups Minimal Preserve all functional data
Development datasets Moderate Good balance for testing
Prototypes/demos Aggressive Size matters more than accuracy
Transfer large logs Moderate Keep essential info, reduce size
Archive old data Minimal Future recovery may be needed

Tips for Maximum Compression:

API Reference

For programmatic access, see the API Endpoints section on the homepage.

← Back to Home

↑