Multiple html pages having same java script file import

Hi, I have problem with java script file import, I have multiples pages in same project. Say i have master.html, slave1.html,slave2.html ,slave3.html. If i have a javascript like main.js in master, its imported in remaining slaves which i dont want to happen. How can i avoid that ? Since this is happening right now, everything kind of runs into infinite loop.

Thanks in advance.

I thought i should elaborate on this. Am trying to create a single page website, with tab based navigation. But in order to maintain modularity, i have created slave1.html,slave2.html,slave3.html as part of master.html, am loading them inside master.html inside respective tabs. When i do this, i want to run the script(main.js) only once to load these slave htmls,but rather its imported in all slaves, its kind of creating infinite loop.

Just so you know it's pretty common to have every page on your site include the same scripts on them. It helps with caching which reduces HTTP requests which can slow down the loading of your site.

I don't know exactly what your script is trying to do an also I'm not an expert script writer either. I'd try switching from the script executing on page load an only execute when it finds a certain ID. That ID should only be on the master.html page most likely on the body element.

example something like:

$("#imthemasterpage").on("load",function(){
    // I want to do my script tricks here
});

You might just have to correct your issue as a post export fix, where your slave pages only contain the content needed, not the entire website code.

Saj