Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda