question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dedupe script paths and/or how to inspect in-flight requests?

See original GitHub issue

I’m using loadjs to async load the Select2 jQuery plugin (https://select2.github.io/) that I use for 2 different use cases: 1) search autocomplete 2) location suggestions. The location suggestions depends on another data adapter, but both cases need the same plugin files other than that:

loadjs([
  '/js/select2.js',
   '/css/select2-theme.css'
], 'select2', {
   success: initKeywordAutocomplete
});

loadjs([
  '/js/select2.js',
  '/js/select2-places.js',
  '/css/select2-theme.css'
], 'select2-places', {
  async: false,  // load in series to ensure select2 is available before the places data adapter
  success: initLocationAutocomplete
});

If I use the above code on a page, select2.js, select2-theme.css will both be added to the DOM twice, and select2-places.js will only be added once.

First, is it reasonable to add an enhancement to loadjs that dedupes the scripts added to the DOM? Currently only bundles are deduped by their id’s, but I’m thinking of saving the script paths too so they aren’t appended to the DOM more than once.

Second, I can see why it would be a bad idea to expose the bundle dependency tracker objects, and instead have the .reset() function to let users clear them out. But, is there a way to inspect the requests loadjs has initiated? Or should I just query the DOM for a script tag for the src I want to avoid downloading twice?

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
amoreycommented, Feb 23, 2017

Thanks for the feedback! It would return true after the bundle is registered. The .ready() method can be used to execute a callback after the dependencies have been loaded.

1reaction
amoreycommented, Feb 22, 2017

Hi @akrawchyk - sorry for the late response. I have a working version with a new isDefined() method:

<script>
  if (!loadjs.isDefined('my-bundle')) {
    loadjs(['1.js', '2.js'], 'my-bundle');
  }
</script>

Let me know if this would solve your problem and if you have any suggestions for the method name and syntax.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Untitled
Gerber prodigy test, Former residence of popes in rome, Sara beirami, ... in washington state, Kikka sushi tiger roll, Haines reverse phone directory?...
Read more >
Untitled - Snap!
... ,symptoms,plenty,select,french,memory,glass,operations,request,path,ugg ... ,opinions,frequent,flexibility,laser,harry,logo,script,bound,hunting,calm ...
Read more >
quality-driven software architecture: Topics by Science.gov
This makes the roadmap applicable to any specific solutions of MPI, deduplication library or software platform. Stakeholders in need of integration of MPIs ......
Read more >
docu45657_Avamar-Data-Store-Gen4S-Comprehensive-Reference ...
Check the EMC Online Support Site toensure that you are using the latest version of ... such as an error message or script•URLs,...
Read more >
Untitled
Colombia peru game online, Serralharia cunha, Marcinek chmielecki, Payton smades, Aes ecb 128 test vectors, Arteritis viral equina vacunacion, Ostad hassan ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found