Hi,
I am trying to deploy a Phoenix application and everything seems quite straightforward. It loads with all the assets, except I am being stuck at the assets being loaded being the non-gzipped versions, which of course slows down things tremendously.
I am looking at making the following setup work: deploying a mix release
to an AlpineJS server (works), uploading assets to a DigitalOcean Space with CDN enabled (works) and then making the application use those assets (works, but).
For that, my setup is as follows:
In config/releases.exs
, I have added static_url: [scheme: "https", port: 443, host: "assets.example.dev", path: "/static"]
to the ExampleWeb.Endpoint
config.
For asset loading, in the root template layout, I have
<link
phx-track-static
rel="stylesheet"
href="<%= Routes.static_url(@conn, "/css/app.css") %>"
/>
<script
defer
phx-track-static
type="module"
src="<%= Routes.static_url(@conn, "/js/app.js") %>"
></script>
I run yarn deploy --cwd assets
and mix phx.digest
, which correctly builds all the assets into priv/static
, attaches a hash and gzips each file. These files are then uploaded to the Space (S3 compatible). The created cache_manifest.json
is then uploaded to the server.
Now, all of that works quite well and the correct assets are loaded properly, except that I would like it to load the .gz
versions from the CDN. They are available and can be accessed, but Phoenix loads the larger, non-gzip ones. Setting gzip: true
in the Static plug doesn’t change anything since the assets are obviously not served by the plug, but by a CDN.
Is there any way to make this work and have Phoenix access the gzip versions?
Cheers and have a great rest of your weekend!