Switch & Shrink

How Online File Compression Works

A behind-the-scenes look at how online compression tools reduce file sizes. Learn about the algorithms, security, and technology involved.

What Happens When You Upload a File

When you drag a file onto an online compression tool like Switch & Shrink, a carefully orchestrated process begins. Understanding this process helps you make informed decisions about which tools to trust with your files and what quality trade-offs to expect.

The journey begins with your browser reading the file from your device and transmitting it over an encrypted HTTPS connection to the server. For large files, this upload is often chunked — broken into smaller pieces that are transmitted sequentially and reassembled on the server. This approach prevents timeouts and allows for progress tracking.

The Compression Pipeline

Once your file arrives on the server, it enters a compression pipeline — a series of processing steps tailored to the file type. Here's what happens for different file types:

Image Compression Pipeline

  1. Format detection: The server identifies the exact image format, color space, and bit depth by reading the file headers.
  2. Metadata extraction: EXIF data, ICC profiles, and other metadata are read and stored separately. Based on your settings, some metadata may be preserved while the rest is discarded.
  3. Color space normalization: Images are converted to a consistent internal representation for processing. CMYK images may be converted to RGB, and color profiles are applied.
  4. Resizing (if requested): The image is resized using high-quality algorithms like Lanczos resampling, which produces sharper results than simple bilinear interpolation.
  5. Compression: The appropriate codec encodes the image at the specified quality level. For JPEG, this involves DCT (Discrete Cosine Transform) processing. For PNG, it's deflate compression with filtering. For WebP, it's either VP8 (lossy) or a custom lossless codec.
  6. Output generation: The compressed image is written to the output format with any preserved metadata reattached.

PDF Compression Pipeline

  1. Structure parsing: The PDF's internal structure is parsed — a complex task since PDFs can contain nested objects, cross-references, and multiple content streams.
  2. Resource identification: Embedded images, fonts, and other resources are cataloged with their sizes and compression states.
  3. Image optimization: Each embedded image goes through the image compression pipeline described above. This is usually where the biggest size savings occur.
  4. Font subsetting: Embedded fonts are analyzed, and unused glyphs are removed to reduce font data size.
  5. Stream recompression: Content streams within the PDF are recompressed using efficient algorithms.
  6. Linearization: The PDF is restructured for efficient loading, with redundant objects removed.
  7. Output generation: The optimized PDF is assembled and written to disk.

Compression Algorithms Explained

Lossy Compression: Controlled Quality Reduction

Lossy compression works by identifying and removing information that humans are least likely to notice. For images, this exploits the fact that human vision is more sensitive to brightness differences than color differences, and more sensitive to large-scale patterns than fine detail.

The JPEG algorithm, for example, converts the image from the RGB color space to YCbCr (luminance and chrominance), downsamples the color channels (since we're less sensitive to color detail), divides the image into 8x8 blocks, applies a mathematical transform (DCT) to each block, and then quantizes the results — rounding small values to zero. The degree of quantization controls the quality-size trade-off.

Lossless Compression: Efficient Encoding

Lossless compression finds more efficient ways to represent the same data. PNG uses two techniques in sequence: filtering (predicting each pixel based on its neighbors and storing only the difference) and deflate compression (finding and replacing repeated patterns with shorter references).

Lossless compression doesn't discard any data — every pixel is preserved exactly. The trade-off is that compression ratios are more modest, typically 2:1 to 5:1 for photographic images, compared to 10:1 to 50:1 for lossy compression.

Modern Codecs: WebP and Beyond

WebP uses more sophisticated techniques than JPEG, including variable-size blocks (instead of fixed 8x8), more prediction modes, and arithmetic coding (which is more efficient than JPEG's Huffman coding). These advances allow WebP to achieve 25-35% better compression at the same visual quality.

Security and Privacy

A legitimate concern with online compression is: what happens to your files? Responsible services like Switch & Shrink implement several security measures:

  • Encrypted transmission: Files are uploaded and downloaded over HTTPS, preventing interception.
  • Automatic deletion: Uploaded and processed files are deleted from the server shortly after download or after a short timeout period.
  • No account required: No personal information is collected, which means there's nothing to breach.
  • Server-side processing: Files are processed in isolated environments and not accessible to other users.
  • No storage: Files are not stored permanently — they exist on the server only for the duration of the processing and download window.

Client-Side vs. Server-Side Processing

Some compression tools process files entirely in your browser using JavaScript and WebAssembly. This approach offers maximum privacy since files never leave your device. However, browser-based processing is significantly slower than server-side processing, especially for large files or complex operations like PDF optimization.

Server-side processing, used by Switch & Shrink, leverages powerful libraries and hardware to process files much faster. The trade-off is that files must be uploaded to the server, which is why encryption and automatic deletion are important.

A hybrid approach is also possible: simple operations like basic image resizing happen in the browser, while complex operations like PDF restructuring are handled server-side.

Quality Control and Optimization

Advanced compression tools don't just apply a single compression level to your entire file. They analyze the content and make intelligent decisions about how to compress different parts. For a PDF, a photograph might be compressed at 75% JPEG quality, while a chart with text might be kept at 90% to preserve readability.

This content-aware approach is what separates good compression from great compression. A naive tool might produce a smaller file, but at the cost of making text illegible or photos unrecognizable. A smart tool finds the optimal balance for each piece of content in your file.

What to Look for in a Compression Tool

When choosing an online compression service, consider these factors:

  • Transparency: Does the tool explain what it does with your files?
  • No account required: Requiring sign-up adds friction and means your files can potentially be tied to an identity.
  • Before/after comparison: Can you verify the quality of compressed files before downloading?
  • Batch processing: Can you process multiple files at once?
  • Format flexibility: Does it support the formats you need, and can it convert between them?
  • Auto-deletion: Are your files cleaned up after processing?

Switch & Shrink meets all these criteria: transparent processing, no sign-up, before/after previews, batch support for up to 20 files, multiple format support, and automatic file deletion. It's designed to be the tool you reach for whenever you need to make files smaller.