Answer the question
In order to leave comments, you need to log in
How to include scripts in BEM?
Good afternoon.
Suppose there is block A with its script A.js, it is part of block B.
What do you think is the best way to connect A.js?
1) Is it worth it to connect it using import to B.js
2) Or is it worth creating a main.js file and importing scripts of all blocks there?
The first method is bad because on the page where there are blocks B and C, the A.js script will be duplicated.
The second method is bad because if I connect main.js to each page, then those scripts that are not needed on this page will also be connected.
I would like to get your opinion.
PS
So far, I'm not familiar with the assemblers, so I would like to hear a simple solution.
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Blocks must be independent of each other. If something depends on the block, then it is better to make it an element or a modifier.
But if you have a separate JS file for each element and each modifier, then it is better to connect it in the second way. If you decide to do everything according to different files, then it is probably better to include each file separately, especially since there will be less manual work if all the necessary blocks / elements / modifiers are automatically included by the assembler. No need to write imports manually for each element / modifier.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question