Francis. Static
(Francis v0.4.0)
View Source
Utilities for working with static assets.
This module provides functions to resolve static paths and URLs, including
support for digested assets generated by mix francis.digest.
The decoded manifest is cached in :persistent_term, keyed by its path, and
reloaded only when the file's mtime, size or inode changes (e.g. after re-running
mix francis.digest, which replaces the manifest atomically via rename, so the
inode changes even when a rewrite lands in the same second with the same size).
Summary
Functions
Returns all assets from the manifest.
Returns the cache-control header value recorded by mix francis.digest --age,
or nil when the manifest is missing or has none.
Checks if an asset exists in the manifest.
Loads the cache manifest from the given path.
Returns the path for the given asset.
Functions
Returns all assets from the manifest.
Examples
iex> Francis.Static.all()
%{
"app.css" => %{
"digest" => "a1b2c3d4",
"digested_path" => "app-a1b2c3d4.css",
"size" => 1024
}
}
Returns the cache-control header value recorded by mix francis.digest --age,
or nil when the manifest is missing or has none.
Examples
iex> Francis.Static.cache_control()
"public, max-age=31536000, immutable"
Checks if an asset exists in the manifest.
Examples
iex> Francis.Static.exists?("app.css")
true
iex> Francis.Static.exists?("nonexistent.css")
false
Loads the cache manifest from the given path.
Returns {:ok, manifest} on success, {:error, reason} on failure.
Examples
iex> Francis.Static.load_manifest("priv/static/cache_manifest.json")
{:ok, %{"version" => 1, "files" => %{...}}}
iex> Francis.Static.load_manifest("nonexistent.json")
{:error, :enoent}
Returns the path for the given asset.
If a digest manifest is available and the asset is found in it, returns the digested path. Otherwise, returns the original path.
Examples
iex> Francis.Static.static_path("app.css")
"/app-a1b2c3d4.css"