Documentation
¶
Overview ¶
Package assets provides runtime resolution of fingerprinted asset paths.
During the build process, Vango generates a manifest.json mapping source asset names to their fingerprinted (hashed) versions:
{
"vango.js": "vango.a1b2c3d4.min.js",
"styles.css": "styles.e5f6g7h8.css"
}
This package loads that manifest and provides resolution functions for use in templates and components:
manifest, _ := assets.Load("dist/manifest.json")
resolver := assets.NewResolver(manifest, "/public/")
// In component:
Script(Src(ctx.Asset("vango.js")))
// Outputs: <script src="/public/vango.a1b2c3d4.min.js">
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Manifest holds the mapping from source asset paths to fingerprinted paths. It is safe for concurrent use.
func Load ¶
Load reads a manifest.json file and returns a Manifest. The manifest file is expected to be in JSON format: {"source.js": "source.abc123.js"}
If the file does not exist or cannot be read, an error is returned. In development, you may want to ignore the error and use NewPassthroughResolver.
func NewManifest ¶
func NewManifest() *Manifest
NewManifest creates an empty manifest. Use Load() to create a manifest from a JSON file.
type Resolver ¶
type Resolver interface {
// Asset resolves a source asset path to its full URL path.
// This includes any configured prefix and fingerprinted filename.
//
// Example:
// resolver.Asset("vango.js") → "/public/vango.a1b2c3d4.min.js"
Asset(source string) string
}
Resolver provides asset path resolution. It combines manifest lookup with path prefixing.
func NewPassthroughResolver ¶
NewPassthroughResolver creates a resolver that returns paths unchanged. Use this in development mode where fingerprinting is disabled.
The prefix is still applied, so dev and prod paths remain consistent:
// Development:
resolver := assets.NewPassthroughResolver("/public/")
resolver.Asset("vango.js") // "/public/vango.js"
// Production:
resolver := assets.NewResolver(manifest, "/public/")
resolver.Asset("vango.js") // "/public/vango.a1b2c3d4.min.js"
func NewResolver ¶
NewResolver creates a Resolver from a Manifest with an optional path prefix.
The prefix is prepended to all resolved paths. Common prefixes:
- "/public/" - standard static file path
- "/assets/" - alternative static path
- "" - no prefix (use fingerprinted name directly)
Example:
manifest, _ := assets.Load("dist/manifest.json")
resolver := assets.NewResolver(manifest, "/public/")
resolver.Asset("vango.js") // "/public/vango.a1b2c3d4.min.js"