I connect to the JavaScript site with one file, it contains functions for initializing the carousel, lightbox, Yandex card and so on. All code (except for certain functions) lies in document.ready (jQuery is connected).
Naturally, not all parts of the code are used on all pages. Say, the carousel is needed only on the main one, and the map is only in the "contacts". As I understand, all the code works on all pages. Does it make sense to insert checks for the presence of certain elements, say, initialize the carousel only if there is a div with id=#fotorama , or just connect different js to different pages? Or does js / jQuery automatically perform these checks and this does not affect the speed / reliability of the scripts?