Custom js files and folders in Phoenix Framework

Thanks for all for the response

In the default setup your js files are concatenated into app.js which can be accessed on localhost:4000/js/app.js, for example.

Note that in order to have your static files served, you should probably run a server.

1 Like

I just looked at sipml5 documentation and it doesn’t provide installable NPM packages, so instead we need to go the old way. It seems to me that you need the SIPml-api.js (which I assume you have downloaded), and including that file will define some global variables (SIPml).

I believe this is precisely the case of Legacy Non-modularized Code section of the Phoenix guides. What you need to do is put the SIPml-api.js file to web/static/vendor. Phoenix (through Brunch) will include that file just before your code (from web/static/js) in the resulting concatenated file priv/static/js/app.js, which means that all the variables defined will be available for your own JS code.

You can then use the SIPml.init etc. from your web/static/js/app.js file. Can you try if it works?

1 Like

I think you’re including the wrong file, specifically you are including the debug version of SIPml-api.js which dynamically appends scripts with reference to local files (SIPml.js and src/tinySIP/src/tsip_api.js). You don’t have these two files, that’s why Phoenix is complaining that no route is found for them.

Try going to the github page. At the very bottom, there is “Download JS API” link and it refers to the concatenated, production build of SIPml-api.js. I think that should work.

1 Like

Glad you got it working!