kubetail-org / loadjs

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

Mix & Match Synchronous and Asynchronous calls? #52

Closed thisissami closed 7 years ago

thisissami commented 7 years ago

Hello,

I'm trying to mix and match my synchronous and asynchronous calls. I have 3 css files that can be loaded in any order, and 2 JS files that need to be loaded in a particular order. I'm trying to do the following:

loadjs(['https://unpkg.com/leaflet@1.2.0/dist/leaflet.css',
    'https://unpkg.com/leaflet.markercluster@1.1.0/dist/MarkerCluster.css',
    'https://unpkg.com/leaflet.markercluster@1.1.0/dist/MarkerCluster.Default.css'
  ], 'css');
loadjs(['https://unpkg.com/leaflet@1.2.0/dist/leaflet.js',
    'https://unpkg.com/leaflet.markercluster@1.1.0/dist/leaflet.markercluster.js'
  ], 'js', { async: false });

loadjs.ready(['css, js'], {
  success: function() {
    console.log('Woohoo! everything loaded!');
    document.body.appendChild(main);
  },
  error: () => {
    console.log('ruh-roh... something went wrong!');
  }
}); 

The files all seem to load properly like this, but the loadjs.ready() function never runs. Is there any way to properly do what I'm trying to do here?

amorey commented 7 years ago

It looks right so it took me a little while to spot the bug. There's a typo in ['css, js']. It should be ['css', 'js'].

amorey commented 7 years ago

@thisissami Also, I should note that async=false doesn't impact CSS files so you can load all the files in one function call without impacting the performance or behavior.

thisissami commented 7 years ago

oh!! whooops ok well that's silly mistake I made them. :P Damn those programming mistakes that you don't notice cuz everything looks fine at first glance. :P I am glad to know that this is uneccessary though, and accordingly am happy that i fucked up. Thanks for the super quick response!!