JS files in Phoenix Project

That should work the same if you manually load the file; if I’ve got this right: you have a function or method in a JS file. It’s global. In an arbitrary HTML file you’re waiting for the document to load so that you can guarantee the function is available. You’re running the function.

Rails does what it does via the Sprockets library; it is importing the JS you referenced in application.js via magic. What you’ve done by saying --no_brunch is remove the equivalent to Sprockets from Phoenix. It can’t load your file automatically because you’ve removed the thing that would allow it; by default, with brunch, you get a main JS file that you can import other JS files into (and it has to be specified explicitly; it doesn’t do magic like Rails). Without brunch, you need to manually import every JS file into the head or foot of your HTML