enable gzip on Plug.Static unconditionally

Plug.Static with gzip: true serves .gz files when they exist
(created by phx.digest) and falls back to uncompressed otherwise.
The previous code_reloading? guard was needlessly conservative —
in dev without digested assets, there are no .gz files so nothing
changes. With the lighthouse task building prod assets, this gives
realistic transfer sizes (42KB JS vs 135KB).

Mobile lighthouse scores jump from 95-97 to 99-100.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey 2026-02-08 18:23:53 +00:00
parent 516d0d0070
commit 1f4e938ed1

View File

@ -16,18 +16,12 @@ defmodule SimpleshopThemeWeb.Endpoint do
longpoll: [connect_info: [session: @session_options]] longpoll: [connect_info: [session: @session_options]]
# Serve at "/" the static files from "priv/static" directory. # Serve at "/" the static files from "priv/static" directory.
# # gzip is always enabled — Plug.Static serves .gz files when they exist
# When code reloading is disabled (e.g., in production), # (created by `mix phx.digest`), falls back to uncompressed otherwise.
# the `gzip` option is enabled to serve compressed
# static files generated by running `phx.digest`.
#
# Cache headers: 1 year for all static assets. Digested assets (with hash
# in filename) use `immutable`. Fonts/mockups/images rarely change and
# benefit from aggressive caching.
plug Plug.Static, plug Plug.Static,
at: "/", at: "/",
from: :simpleshop_theme, from: :simpleshop_theme,
gzip: not code_reloading?, gzip: true,
only: SimpleshopThemeWeb.static_paths(), only: SimpleshopThemeWeb.static_paths(),
cache_control_for_etags: "public, max-age=31536000, immutable" cache_control_for_etags: "public, max-age=31536000, immutable"