kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.57k stars 149 forks source link

How to Solve the Problem of Repeated Loading of Scripts #100

Open csq2018 opened 4 years ago

csq2018 commented 4 years ago

(CV ON%%{%T}6`KPWVCD)FN SH4(W DV6Q{K6SRW)4LK J9

Every time I click to trigger the _confirm page, I insert confirm.js how to solve this situation?

amorey commented 4 years ago

What is the desired behavior? On the second click do you want to execute the callback without loading the script?

bhawan-eco commented 4 years ago

I have the same issue. multiple visits to a page causes repeated download/adding or same file by LoadJS. Is there a way to remove the previous file before re-adding them?

amorey commented 4 years ago

You can use the .isDefined() method:

if (!loadjs.isDefined('foo')) {
  loadjs('/path/to/foo.js', 'foo', function() { /* foo.js loaded */})
}