webstatic

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webstatic sends the built files of a page gzipped to browsers that take it. The compressed copy of a file is made once and kept in memory; a file that changes on disk gets a new copy. Files under 1 KB, Range requests and types that are already compressed go out as they are.

Index

Constants

View Source
const MinBytes = 1024

MinBytes is the size below which a body is not worth compressing.

Variables

This section is empty.

Functions

func AcceptsGzip

func AcceptsGzip(r *http.Request) bool

AcceptsGzip is true when Accept-Encoding lists gzip with a quality above zero.

func Gzip

func Gzip(raw []byte) []byte

Gzip compresses raw at the level used for the page's files.

func WriteBody

func WriteBody(w http.ResponseWriter, r *http.Request, raw, gz []byte)

WriteBody sends a body made for this request (a rendered page), gzipped when it is worth it and the browser takes it. The caller sets the type and the cache rule first; gz, when not nil, is the body compressed beforehand.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache keeps the tags and gzipped copies of a page's files. The zero value is ready to use.

func (*Cache) Serve

func (c *Cache) Serve(w http.ResponseWriter, r *http.Request, files fs.FS, name string) bool

Serve answers for one file of the page: its type, its cache rule (files under assets/ are named by their content), a tag that differs between the plain and the gzipped copy, and the gzipped copy when the browser takes it. It reports false, having written nothing, when the file cannot be read, so the caller can fall through to the page's own routes.

Jump to

Keyboard shortcuts

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