Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
What happens when a script source is loaded multiple times?

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?

  • It detects duplication and only executes the first line?
  • It executes all the lines, but detects that the same file URL has been visited, so it doesn't download again?
  • It executes all the lines, but detects that the same file name has been downloaded, so it doesn't download again?
  • It executes all the lines, but detects that the same file content has been downloaded, so it doesn't download again?

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?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!