kubetail-org / loadjs

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

Support loading scripts with "crossorigin" atrribute #66

Closed debopamsengupta closed 6 years ago

debopamsengupta commented 6 years ago

Hello :) would it be possible to add support for adding a crossorigin property to scripts being loaded using loadjs .

This is mainly because if these scripts end up having errors, consumers of such scripts only end up with non-descriptive Script error. messages.

I'd be happy to make a PR with this feature.

amorey commented 6 years ago

You can add a crossorigin property to each script using the before callback:

loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
  success: function() {},
  error: function(pathsNotFound) {},
  before: function(path, scriptEl) {
    /* called for each script node before being embedded */
    if (path === '/path/to/foo.js') scriptEl.crossOrigin = true;
  }
});

(See example 14 here: https://github.com/muicss/loadjs)

debopamsengupta commented 6 years ago

awesome thanks :)