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 ¶
const MinBytes = 1024
MinBytes is the size below which a body is not worth compressing.
Variables ¶
This section is empty.
Functions ¶
func AcceptsGzip ¶
AcceptsGzip is true when Accept-Encoding lists gzip with a quality above zero.
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 ¶
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.