How to load js script in Phoenix?

How can I load a js script when I start the phoenix server (iex -S mix phx.server). It will load only after entering the index page. I don’t need to enter the website but I have to use the functionality of the js.

Phoenix doesn’t have anything to do with JS.

  • node/npm is used as tooling for building assets used by the page inside the browser (and some development support like live reloading).
  • Other than that JS files are sent to the browser for execution.

Maybe this might be of interest:

1 Like

To run javascript from on the phoenix side and not the front-end you can either run it in-system directly with V8 like with this or you can have nodejs run it via a port or so.