Search code examples
elixirphoenix-frameworkplug

Elixir Plug gzip not working for pngs


I have

plug Plug.Static,
  at: "/pros",
  from: :zipbooks,
  gzip: true,
  cache_control_for_etags: "public, max-age=604800",
  only: ~w(css assets fonts images js favicon.ico robots.txt)

and my js css and svg files are being served with content-encoding:gzip but my png files, served the same way, are not.

Here's an example of an svg and how its gzipped:

enter image description here

and heres a png

enter image description here


Solution

  • You need to add .png to gzippable_exts config as mentioned in the docs here.

    We can optionally determine which files should be gzipped by using the :gzippable_exts option in the config file:

    config :phoenix, :gzippable_exts, ~w(.js .css)
    

    It doesn't make sense to compress png files though since they're already compressed which is why the default gzippable_exts doesn't include it.