Documentation
¶
Overview ¶
Package pwbrowser is the browser runtime this framework ships, and where a document finds it.
It is a leaf because both transports serve the same bytes under the same URL, and they have to: a document naming the runtime is rendered by whichever half is running, and an application's own template names that URL once. Two runtimes each embedding their own copy would be two revisions of one asset, and a page rendered by one build would load a script the other does not serve.
What is not here is the serving. Reading a path and writing a response is a transport's work, so each supplies that over Lookup.
Index ¶
- Constants
- func Claims(path string) bool
- func ContentType(name string) string
- func Lookup(path string) (source, contentType string, ok bool)
- func Publish(extra map[string]string, extraImport string)
- func Revision() string
- func RuntimeScriptURL() string
- func RuntimeSource() string
- func ScriptURL(name string) string
- func Scripts() map[string]string
Constants ¶
const CacheControl = "public, max-age=31536000, immutable"
CacheControl is what an asset under a revision segment carries. The segment never serves different bytes, so this is genuinely immutable rather than merely long-lived.
const Prefix = "/_pw/"
Prefix is reserved for framework-owned browser assets. It is a fixed absolute path rather than a subtree of the configurable public mount, because these belong to the framework rather than to the application, and because the document shell has to be able to name one without reading configuration.
const RuntimeName = "popcornweb-runtime.js"
RuntimeName is the module a document loads.
Variables ¶
This section is empty.
Functions ¶
func Claims ¶
Claims reports whether path is inside the reserved namespace at all, which is what a transport uses to close it.
func ContentType ¶
ContentType picks a type from the name a module was registered under.
The set held nothing but JavaScript until the development launcher brought its mark along, and the name is the only thing to read it from: the bytes are held as strings, and sniffing them would be guessing at what the file name already states. The set is closed and this build wrote every name in it, so an unrecognised one is a module rather than something to refuse.
func Lookup ¶
Lookup answers what a request for path should be served, and whether this build claims it at all.
Only the modules of the current set are claimed. The prefix holds more than the script assets — a package asset lives here too — so claiming the whole namespace here would swallow every route that arrived after this one. A transport closes the namespace below all of them.
A stale revision is therefore not found rather than served from the current set, which is what makes the immutable caching sound.
func Publish ¶
Publish adds the modules a build serves beyond the core, and the import line the core carries to reach them.
It exists for the development build mode, which adds a module and an import and must therefore land on a different revision — with no constant for anybody to bump, and no chance of a browser holding the release URL immutably and receiving development bytes under it.
A build that adds nothing calls nothing, which is every deployed build.
func Revision ¶
func Revision() string
Revision digests the script set so a changed dependency changes every URL.
Deriving it from the bytes rather than from a release constant means an upgrade that changes the runtime cannot ship under a URL a browser already cached forever.
func RuntimeScriptURL ¶
func RuntimeScriptURL() string
RuntimeScriptURL is the absolute path of the boundary runtime module. A document template names it through a declared external function rather than as a literal, so the template text survives an upgrade that moves the URL.
func RuntimeSource ¶
func RuntimeSource() string
RuntimeSource is the core module's bytes, before whatever a build mode appends. It is exported for a test that reads what shipped rather than what a set was assembled into.
func ScriptURL ¶
ScriptURL is the absolute path of one module in the set. Modules share one revision segment so that imports between them stay ordinary relative specifiers and nothing has to rewrite them.
Types ¶
This section is empty.