javascript - Can I Load CSS Using the "load.js" Library? -


i found out load.js, can't seem find indication of whether or not possible... (note: can't find 'load.js' tag..)

i've got load.js loading js files, know works. has got working loading css files well?

update: remyabel's solution worked loading physical files, seems there few quirks process...

for reason, order in css files loaded , whether they're done in 1 load(file1,file2); or in stages load(file1).then(file2); seems affect how style rules applied markup. i'm going set few test cases on local machine try work out how or why happens, @ least files being loaded.

final note:

following on solution posted below, i've decided use head.appendchild(script); instead of head.insertbefore(script, head.firstchild); add css elements dom (still uses original method js files).

this doesn't affect order in files fetched , processed, makes load.js insert css links in same order listed , @ end of header instead of beginning.

direct source code

   function asyncloadscript(src) {         return function (onload, onerror) {             var script = document.createelement('script');             script.type = 'text/javascript';             script.src = src; 

my suggestion modify script (which doesn't seem contain much) mirror function link tag, rather script tag.

to reflect op's comment

the script built on top of chain.js may more complicated expected.

unless want else, i'm pretty sure wrote above need change, like:

   function asyncloadscript(src) {         return function (onload, onerror) {  // file extension var ext = src.split('.').pop(); if (ext == "js") {                 var script = document.createelement('script');                 script.type = 'text/javascript';                 script.src = src; } else if (ext == "css") {                 var script = document.createelement('link');                 script.type = 'text/css';                 script.href = src;                 script.rel = "stylesheet"; } 

theoretically should work. make comment if doesn't work.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -