Storehouse.Variants.Plug (Storehouse v0.2.0)

Copy Markdown View Source

Serves variants (Storehouse.Variants) at the URLs Storehouse.variant_url/3 gives, making each the first time it is asked for: GET <at>/<original key>/<preset>-<width>-<fingerprint>.

In the endpoint, before the router:

plug Storehouse.Variants.Plug

or in a router, where forward strips the path:

forward "/variants", Storehouse.Variants.Plug, at: "/"

Only a preset's widths are made: any other size, preset or key gives 404, as does an original that is not there, or not an image. A fingerprint of a preset since changed is redirected (302) to the preset's current URL. The format of a preset of several is chosen by the request's Accept, with Vary: Accept.

A variant is sent with Cache-Control: public, max-age=31536000, immutable: its URL changes when its preset does, so a CDN in front keeps it for a year.

Options

  • :at - the request path. The default is the configured :url ("/variants").
  • :only - which originals have variants: a list of key prefixes, or a function of the key. The default is every key with a preset's name, width and fingerprint: originals that must stay private (served only at signed URLs) are left out with it.
  • :cache_tag - true sends the original's Cache-Tag (Storehouse.Purge.cache_tag/1) with each of its variants, for a purge by tag.
  • :adapter - the store. The default is Storehouse.adapter/0.
  • The configuration's (:presets, :renderer, :prefix).