How do I turn off static assets digest and what does cache_static_manifest do exactly?

a bit of background,

  • I’m working on a project that has its own js build pipeline, and the build output already includes a digest hash in their names. Running mix phx.digest would append another layer of digest to the file names. I wanted to include script tags without this second digest.
  • When the app is running under prod env/build, generating static paths with Routes.static_path(conn, "app.build_digest_ad21d.js") produces outputs like app.build_digest_ad21d.phx_digest_sd212.js.
  • I was able to disable this behavior by removing the cache_static_manifest from the endpoint config, and get the static paths I want without the extra digest.

so, my questions here are, what does cache_static_manifest do exactly and how does it affect the static server? The name seems to suggest it has something to do with caching? Does it control how the static server cache the files in memory or something?

Running mix phx.digest seems to also generate the gzipped version of the static files. Would disabling this manifest means the static server have to compress all the static files on the fly everytime?

If anyone can point me to someplace that documents this behavior, that would be very helpful as well. I could only find the mention on Phoenix.Endpoint that says it points to the json manifest file, but there is no mention on how this json manifest file itself gets used or how it affects the Plug.Static

This file contains a mapping of the resource url with the real file name: /assets/js/jquery.js that your templates use and the target is the digested file, Phoenix will lookup the requesting path /assets/js/jquery.js in this json and respond with the digested file. If Phoenix is not serving static assets you can remove it. If Phoenix is serving assets and your js pipeline builds one json file that maps the normal file name to the digested in the file system you can pass it to cache_static_manifest, e.g.: cache_static_manifest: "/priv/custom-manifest.json"

Since you already have a js pipeline with digestion you don’t need to run mix phx.digest

I’m not generating my own manifest file, at least not the one that is used by by Phoenix, though I might consider that if I really need to. Is the format/spec documented anywhere?

More to the point, I suppose my question really is more like; can I do without the cache_static_manifest file at all? Aside from the static links being generated without the digest, is there any other side effect from this?

Are you including hardcoded your using Routes.static_path/2 ? if is the latter you can append another digest and let phoenix handle the digest. Or you could remove the digest from the js build pipeline and let only Phoenix’s.

The browser would not benefit from caching or downloading the gzip version of the static resource.

Not that I could find.

Yes, it would not be optimal because of the cache, but you can.

I’m pretty certain I can still get the gzipped version of the assets by setting gzip: true on Plug.Static, I’ve tested this and I am getting the gzipped version with the above settings even without running phx.digest or including any manifest file.

Yes, it would not be optimal because of the cache, but you can.

Can you clarify what do you mean by “cache” here? how is the manifest used for caching?

The browser cache.

Oh yes, if you do that Plug will look for a gz version of the requested file, that works too