How to add only used js to the page?

  • 0
    I use gulp and webpack to build. I used to make only one-page websites. so I collected all the scripts into 1 file and everything worked fine.

    Right now I am making a multi-page site and ran into a problem: On one page I need to use a script, and on the other not. On the page where the script is not needed, an error appears due to the absence of an element to which it refers and from this all js stops working:

    In fact, many js files are stored inside BEM blocks (folders), and it would be cool to add them only when using. How can this be done and how to do it correctly?
    JavaScript Vivian McMillan, Nov 11, 2020

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!