kubetail-org / loadjs

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

CSS order #105

Closed sergejostir closed 3 years ago

sergejostir commented 3 years ago

Hello.

Is it possible to specify before which element should css be put to? I'm thinking like "before" in https://github.com/filamentgroup/loadCSS

I would like to dynamically load a css file before already loaded one, but this library seems to always put new elements at the end of existing ones.

amorey commented 3 years ago

You can use a before callback to control when/where the CSS is placed:

loadjs("/path/to/file.css", {
  before: function(path, el) {
    // insertion logic goes here
    document.head.appendChild(el);

    // return `false` to bypass default DOM insertion mechanism
    return false;
  }
});

Hope that helps. Let me know if that works for you.

sergejostir commented 3 years ago

Ah, of course. Makes sense. Thanks