kubetail-org / loadjs

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

Custom script attributes #89

Closed jsardev closed 5 years ago

jsardev commented 5 years ago

It's often needed to pass custom attributes to the script tag. It would be great if loadjs would support such a usecase.

Maybe an attributes option would do the work?

amorey commented 5 years ago

To add custom attributes you can use 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;
  }
});
jsardev commented 5 years ago

Oh, didn't think about this :D Thanks!

amorey commented 5 years ago

No prob! Happy to help.