Prod assets and file uploads

I'm trying to get my head around how static assets work in a production environment, the documentation seems pretty scary, but it can only be me.

According to http://www.phoenixframework.org/docs/deployment , I have to run MIX_ENV=prod mix phoenix.digest as part of my deployment. This seems to duplicate all my assets with a string concatenated with the name, which is then serviced using static_path/2 , I believe this has something to do with caching of the bust during deployment. Excellent!

The digest function also creates manifest.json inside my personal folder, it looks something like this.

{"images/calltoaction.png":"images/calltoaction-13cfefeb09c991b12090bcf0a10f2dd2.png","fonts/fontawesome-webfont.woff2":"fonts/fontawesome-webfont-4b5a84aaf1c9485e060c503a0ff8cadb.woff2","im.....

I believe Phoenix uses this to map assets to their corresponding version. Please correct me if I am completely mistaken. Oh well, to my question.

In my application, administrators can upload images to the admin panel, they are uploaded to /priv/static/images/model/version/.. The problem is that these recently uploaded images are not in the manifest.json file and therefore will not be displayed?

This seems very scared as new images are not displayed, images are not replaced, etc. How would I deal with this problem? Should I upload my images to another place that cannot be digested?

+5
source share
1 answer

manifest is a cache function. It is used by static_path to create links pointing to assets. If you cannot use it for all assets because they are loaded dynamically, you do not need to use it. In other words, you should be able to load your assets and just use static_path , as usual, and they should be serviced, as in development.

+1
source

Source: https://habr.com/ru/post/1232140/


All Articles