Injecting css inside the head from javascript is not loading completely

30 Views Asked by At
const cssJs ='/*here comes my css - the css here is 200kb in size*/';
function CSSString2CSSStyleSheet ( cssJs ) {
const style = document.createElement ( 'style' );
style.innerText = cssJs;
style.title = 'cssJs';
document.head.appendChild ( style );
const {sheet} = style;
return sheet;
}
CSSString2CSSStyleSheet ( cssJs );

The code above is adding a style tag with css from JS and the css is passed to the style tag innerText. But only the half of the css are injected. At the end of the half css ... is added.

0

There are 0 best solutions below