DEV Community

Discussion on: Load specific JS files in Elixir and Phoenix

Collapse
 
popo63301 profile image
Sofiane Baddag

Does this mean that for each request, a JS file is generated? Or is it pre-generated with Webpack?

I don't seem to get it completely.

Collapse
 
ricardoruwer profile image
Ricardo Ruwer

You will have an app.min.js file that was generated by Webpack and contains all your JS code.

But the idea of this guide is to have some kind of rule in our JS code that is similar to this:

if (myCurrentPage == "/contact") {
  // execute this piece code...
}

if (myCurrentPage == "/about-us") {
  // execute this other piece of code...
}

So we'll not execute code that is not necessary for some pages...

There's also a great library that I use sometimes and do almost the same thing: github.com/lucasmazza/page.js

Collapse
 
popo63301 profile image
Sofiane Baddag

Oh okay ! I thought the idea was to create a JS file for each page. Makes sense now !

Thanks Ricardo !