Reputation: 1065
I want to know what happens when you have two js file in one page with same name. I accidentally put two js files with same name on my page and sometimes both would work, other times just one would work and the other wouldn't. When I load the page, firebug doesn't show any error.
So can anybody tell me exactly what happens in such a case? Not that I want to write a thesis on this but just curious.
Upvotes: 0
Views: 2900
Reputation: 4584
I think this is a browser dependant issue, where probably IE will fail (kill me if I'm wrong).
The thing is, these files with the same name, e.g. js.js have to be in different directories, therefore they will be read as different files, nothing should happen or mess up your JS.
If I include the 2 following files with the same name, both would simply work.
<script type="text/javascript" src="dir1/js.js"></script>
<script type="text/javascript" src="dir1/subdir1/js.js"></script>
The browser simply gets the contents of the file and executes what is in them as soon as it's called by a handler etc.
Name should not matter, however you mentioned that it did not work sometimes.
This is probably a common mistake of including the same src
twice.
Hope this helped you.
‐ Sid
Upvotes: 2