static

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(dir string, spa bool, cache CacheOpts) http.Handler

Handler returns an http.Handler that serves static files from dir.

When spa is true, requests for paths that don't match an existing file are served with dir/index.html (SPA client-side routing fallback).

Cache headers use CacheOpts (defaults when empty): hashed bundle prefixes get a long immutable cache; .html and "/" get no-cache; SPA fallback uses the HTML policy.

Precompressed assets: for request path P, if P.br or P.gz exists on disk and the client sends a matching Accept-Encoding token, that file is served with Content-Encoding set (prefer brotli over gzip when both are acceptable). If both uncompressed P and P.br exist, the precompressed file is preferred when the client accepts that encoding. When no precompressed sidecar exists, compressible text types may be gzip-compressed on the fly (small files only; Range requests skip on-the-fly gzip and use plain ServeContent).

Types

type CacheOpts

type CacheOpts struct {
	HTML         string
	HashedAssets string
	Prefixes     map[string]string
}

CacheOpts configures Cache-Control for static.Handler. Empty HTML / HashedAssets use built-in defaults. Prefixes matches longest URL path prefix first (keys may omit a leading slash).

Jump to

Keyboard shortcuts

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