compress

package
v1.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package compress is the v1.11 phase 4 HTTP-compression middleware. Negotiates brotli (preferred) → gzip → identity from the request's Accept-Encoding header; sets `Vary: Accept-Encoding` so caches don't serve a brotli body to a gzip-only client.

Only compresses responses with a compressible Content-Type (text/*, application/json, application/javascript, image/svg+xml). Skips already-compressed media (PNG, JPEG, .min.js + .min.css served from /assets/ are explicit allowlist entries because Tailwind + htmx + Alpine ship as text/javascript without the .min marker).

Minimum body length: 1 KiB. Compressing 200-byte responses costs more CPU than it saves bandwidth.

SSE streams (`text/event-stream`) intentionally pass through unmodified — buffered compression breaks the event-flush semantics the v1.6 bus relies on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware returns the compression middleware. Wraps every non-SSE GET/HEAD/POST response with the negotiated encoder.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL