PhoenixMountable.Assets.Embedded (PhoenixMountable v0.2.1)

Copy Markdown View Source

Assets read, concatenated and gzipped at compile time, and served from memory under content-hashed URLs.

This is the approach of Phoenix LiveDashboard, Oban Web and Lotus Web: the library ships prebuilt CSS and JavaScript in its Hex package, and the host needs no Node.js, no asset pipeline changes and no Plug.Static entry.

assets: {PhoenixMountable.Assets.Embedded,
         css: "priv/static/app.css",
         js: "priv/static/app.js",
         prepend: [:phoenix, :phoenix_html, :phoenix_live_view, :phoenix_mountable]}

Options

  • :at — the path under the mount where assets are served. Defaults to "", so the CSS is at <mount>/css-<md5>.
  • :prepend — JavaScript to put before the :js entry, from the deps: :phoenix, :phoenix_html, :phoenix_live_view and :phoenix_mountable (the PhoenixMountable browser helper). Defaults to [].
  • any other key is an entry: its name, and a source, a list of sources, or a keyword list with :sources and an explicit :content_type. A source is a path relative to the library root, or {app, path} relative to a dependency's directory.

Responses

Each URL names the MD5 of its content, so responses are cached for a year as immutable. A hash this build did not produce (an old node during a rolling deploy, a bookmarked URL) gets a 404 with no-store, rather than the wrong bundle cached for a year. JavaScript responses opt out of Plug.CSRFProtection's cross-origin script check, since the bundle is public.