Framework-agnostic helpers for rendering asset URLs and tags.
These functions depend only on BunBundle.Config and BunBundle.Manifest.
Tag functions return {:safe, iodata} when Phoenix.HTML is loaded, and
plain HTML strings otherwise. URL functions always return strings.
Phoenix users may prefer BunBundle.Component for HEEx-friendly components.
That module wraps these helpers and is only compiled when Phoenix.Component
is present.
Summary
Functions
Returns the fingerprinted URL for path, including asset host and public
path prefix.
Returns "anonymous" when an :asset_host is configured, otherwise nil.
Renders a <link rel="stylesheet"> tag for the given CSS entry.
Renders an <img> tag for the given image asset.
Renders a <script> tag for the given JS entry.
Returns the space-separated SRI attribute value for path.
Returns the URL for a CSS entry, with dev cache busting applied.
Functions
Returns the fingerprinted URL for path, including asset host and public
path prefix.
Returns "anonymous" when an :asset_host is configured, otherwise nil.
Pair with an integrity attribute. SRI on cross-origin fetches requires
anonymous CORS. Same-origin assets skip it, as anonymous mode would strip
credentials for no benefit.
Renders a <link rel="stylesheet"> tag for the given CSS entry.
In the :dev environment, un-fingerprinted local stylesheets get a
?bust=<mtime> query so browsers fetch fresh CSS after each rebuild. SRI and
cross-origin handling match js_tag/2.
Renders an <img> tag for the given image asset.
Defaults the alt attribute to a humanized filename. Pass alt: to
override.
SRI is intentionally omitted. Browsers do not enforce integrity on <img>
and including it triggers avoidable revalidation.
Renders a <script> tag for the given JS entry.
Adds an integrity attribute when the manifest carries SRI hashes, and
crossorigin="anonymous" when an :asset_host is configured. Bundles are
IIFE format, so no type attribute is set by default. Pass defer: true or
any other option to merge into the defaults.
Returns the space-separated SRI attribute value for path.
Returns nil when the manifest entry carries no SRI hashes.
Returns the URL for a CSS entry, with dev cache busting applied.
In the :dev environment, un-fingerprinted local stylesheets get a
?bust=<mtime> query so browsers fetch fresh CSS after each rebuild.