Should I commit priv/static/cache_manifest.json?

The .gitignore from mix ignores /priv/static/assets, meaning that priv/static/cache_manifest.json will be committed by default (which a lot of people definitely do.

But I was looking for how some “authoritative” Phoenix website would do, and when looking at hexpm, they explicitly ignore the whole /priv/static directory.

It’s not clear to me whether this file should be committed or not, and what would be the benefits of doing so. Can anyone help me understanding that? Thanks!

The cache_manifest.json file is used by the Phoenix Endpoint to map logical asset names (e.g. js/app.js) to a digested filename, like js/app-626f173383838f355f445f469c8a8958.js. This is how it knows which file to use when you reference js/app.js in your layout.

If you check in the cache manifest, you run the risk of Phoenix trying to serve the wrong assets, and/or trying to serve files that don’t exist on the production server.

It makes sense to check the file in if you’re also checking in precompiled (aka digested) assets, but since most people probably don’t, I think it makes sense to ignore the cache_manifest.json file, and possibly the entire priv/static directory as you see fit.

Most deployment/CI/CD processes probably run mix phx.digest, causing the cache manifest to be overwritten anyway, but if you want a little bit of safety you can just add it to .gitignore, since it really is pretty easy to mindlessly run mix phx.digest locally and then blindly check in everything.