- // Do cdata sanitization on the provided CSS, and prepend a double newline
- css = $( mw.html.element( 'style', {}, new mw.html.Cdata( "\n\n" + css ) ) ).html();
- $style.append( css );
+ // Also, calling .append() on a <style> tag explodes with a JS error in IE,
+ // so if the .append() fails we fall back to building a new <style> tag and
+ // replacing the existing one
+ try {
+ // Do cdata sanitization on the provided CSS, and prepend a double newline
+ css = $( mw.html.element( 'style', {}, new mw.html.Cdata( "\n\n" + css ) ) ).html();
+ $style.append( css );
+ } catch ( e ) {
+ // Generate a new tag with the combined CSS
+ css = $style.html() + "\n\n" + css;
+ $newStyle = $( mw.html.element( 'style', attrs, new mw.html.Cdata( css ) ) )
+ .data( 'ResourceLoaderDynamicStyleTag', true );
+ // Prevent a flash of unstyled content by inserting the new tag
+ // before removing the old one
+ $style.after( $newStyle );
+ $style.remove();
+ }