Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda