kubetail-org / loadjs

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

control how loaded scripts and stylesheets are appened to the document #40

Closed sourcec0de closed 7 years ago

sourcec0de commented 7 years ago

I have a bit of a niche use-case. By default, the loaded resources are simply appended to the head. I've added an append hook to short circuit that behavior in case you want to control where that resource is embedded. This is useful when you have styles that can override each other based on when they were loaded in the document.

I added a new example under examples/control-how-element-is-appended.html

The idea is I have a css class

.super-green {
  color: green;
}

The resource I am loading has a conflicting class

.super-green {
  color: orange;
}

With the default behavior, anything with super-green as a class would have the color orange. If I am able to control where it is appended to the document I can inject the loaded stylesheet above the original style declaration keeping that style in tact.

sourcec0de commented 7 years ago

I can update the README with an example before this is merged if it's approved.

amorey commented 7 years ago

Fixed via 99c83c44aebe11d4b6db04d2543d8a449ebdedff