Let's say I load a library multiple times:
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
I check the Network tab in the devtool and see that it's only loaded once. This makes sense, but I wonder how exactly the engine handles this?
I read this article, Preventing JavaScript Files from Loading Multiple Times – Michael Kennedy on Technology, and it seems that it will loaded multiple times by default. Am I correct?
For your shown code the script https://unpkg.com/neovis.js@2.0.0-alpha.9 will be executed 5 times.
Whether it will be downloaded multiple times depends on what is sent as a response for the https://unpkg.com/neovis.js@2.0.0-alpha.9 request and on the browser settings.
The server can send ETag or Modification Date headers in combination with caching policy information headers that tell the browser what to be done if the URL is requested another time.
The headers can say that a resource will be valid for a certain time so the browser does not need to do any further requests for that period of time. It however could also say that the browser has to validate the freshness each time using the last received ETag or Modification Date.
All of the major browsers like Firefox, Safari, IE and Opera will cache a Javascript file the first time it is used, and then on subsequent script tags the browser will use the cached copy if it's available and if it hasn't expired. Having said that, caching behavior can usually be altered through browser configuration, so you cannot rely on any kind of caching behavior.
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
<script src="https://unpkg.com/neovis.js@2.0.0-alpha.9"></script>
Regarding the execution of the files, even if the files are indeed cached, you may have problems since the same code will be executed five times. At the very least, this will cause the browser to take more time than necessary and it may produce errors, since most JavaScript code isn't written to be executed multiple times. For example, it may attach the same event handlers multiple times.