Documentation
¶
Overview ¶
Package cssweight measures the CSS a GoFastr page makes the browser fetch or parse: every <style> element in the document and every <link rel="stylesheet"> it names, fetched once each.
Measure works over plain HTTP, with no browser, so a gate can weigh every page an app serves in seconds. Sizes are reported raw and gzip-compressed, each sheet compressed on its own. For a linked sheet that is its transfer size. Inline sheets travel inside the document's one gzip stream, so their figure runs a little high, but it moves only when the CSS does, which is what a cap needs. A gate compares Weight.Gzip against a cap the app picks from today's numbers, so CSS growth has to raise the cap in the same change instead of arriving unnoticed:
w, err := cssweight.Measure(client, base+"/pricing")
if err != nil { t.Fatal(err) }
if w.Gzip() > 20<<10 { t.Errorf("/pricing ships %s", w) }
Each app keeps its own page list and cap, the way axetest and nojstest are used.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sheet ¶
type Sheet struct {
// Source is the linked sheet's resolved URL, or "inline #n" for the
// n-th <style> element (counting from 1).
Source string `json:"source"`
Bytes int `json:"bytes"`
GzipN int `json:"gzip"`
}
Sheet is one stylesheet the page ships.
type Weight ¶
type Weight struct {
Sheets []Sheet `json:"sheets"`
}
Weight is the CSS one page ships.
func Measure ¶
Measure fetches pageURL with c and weighs its CSS. A linked sheet is fetched from the URL the page names, resolved against the page's <base href> or the page itself, and a sheet linked twice counts once. Any answer other than 200, for the page or a sheet, is an error, and so is a redirect, which Measure does not follow: a gate that weighed an error page, or the login page a lost session lands on, would pass for the wrong reason. A sheet that uses @import is an error too, since the CSS it pulls in would go unweighed.
func (Weight) Gzip ¶
Gzip is the compressed size of every sheet together, each compressed on its own.