Inserting a JS in one single page

Hi all,

I need to insert a JS in one single page in my site. I placed it in assets/js/myscript.js. In the body of the page I added:

<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/myscript.js") %>"></script>

However, I always get a 404 Phoenix.Router.NoRouteError. Sure enough I cannot see myscript.js inside priv/static/js.

What am I doing wrong or what am I missing? I tried following this post and this one but I got lost in details.

Could any one please tell me in plain English what is it that phoenix expects us to do in order to use a js function? Is it something that I have to do in webpack.config.js. My apologies in advance but I am not an experience Web developer, this is literally my first Web Site so I am surely not familiar with a lot of details.

Thank you!

You need to put the file in… assets/static/js

1 Like

Awesome, thank you! That was easy enough. So, for my own education, what is assets/js used for then?

It’s for js files used by webpack… while static is for files not bundled, just copied.

1 Like

Very clear. Thank you!