I am new to elixir and phoenix. Now I have trouble with the static assets in phoenix.
I want to add a js file in my page, and I add the following code in my template:
<script src="<%= static_path(@conn, "/js/test.js") %>"></script>
and then create a js file at web/static/js/test.js
.
However, I got the error about test.js
is not found in the browser's console.
I notice there is a priv/static/js
folder, and I try to create the js file at priv/static/js/test.js
.
This time, the error gone.
I am really confuse about this.
What is the different between web/static
and priv/static
? If I need to test my static files in develop environment, where should I put the static files?
and how about the production environment ?
Thanks.
Priv/static contains processed and concatenated files. I.e they will be saved in this folder after the compilation. However check if your Brunch is working as it takes files from web/static. For better understanding i recommend you go through the doc http://www.phoenixframework.org/docs/static-assets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With