From 1f4e938ed1b6174ebfae06a80cf41076c9f88776 Mon Sep 17 00:00:00 2001 From: jamey Date: Sun, 8 Feb 2026 18:23:53 +0000 Subject: [PATCH] enable gzip on Plug.Static unconditionally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/simpleshop_theme_web/endpoint.ex | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/simpleshop_theme_web/endpoint.ex b/lib/simpleshop_theme_web/endpoint.ex index cff1ba9..fdd3484 100644 --- a/lib/simpleshop_theme_web/endpoint.ex +++ b/lib/simpleshop_theme_web/endpoint.ex @@ -16,18 +16,12 @@ defmodule SimpleshopThemeWeb.Endpoint do longpoll: [connect_info: [session: @session_options]] # Serve at "/" the static files from "priv/static" directory. - # - # When code reloading is disabled (e.g., in production), - # 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. + # gzip is always enabled — Plug.Static serves .gz files when they exist + # (created by `mix phx.digest`), falls back to uncompressed otherwise. plug Plug.Static, at: "/", from: :simpleshop_theme, - gzip: not code_reloading?, + gzip: true, only: SimpleshopThemeWeb.static_paths(), cache_control_for_etags: "public, max-age=31536000, immutable"