Small optimization to ResourceLoader's canExpandStylesheetWith()
authorOri Livneh <ori@wikimedia.org>
Mon, 23 Feb 2015 01:07:36 +0000 (17:07 -0800)
committerOri Livneh <ori@wikimedia.org>
Mon, 23 Feb 2015 01:07:36 +0000 (17:07 -0800)
The import CSS at-rule can only go in the very top of a style sheet.
(Technically, the charset at-rule may precede it, but that rule is not valid
for style sheets that are embedded in <style> tags.) So we don't need to scan
the entire CSS text for '@import' -- we just have to make sure that the CSS
text doesn't start with it.

Change-Id: I56c2ebd55d4a7e90dde8e89e76b6d1b52ed004f8

resources/src/mediawiki/mediawiki.js

index 43c6422..90b8503 100644 (file)
                                // Makes sure that cssText containing `@import`
                                // rules will end up in a new stylesheet (as those only work when
                                // placed at the start of a stylesheet; bug 35562).
-                               return cssText.indexOf( '@import' ) === -1;
+                               return cssText.slice( 0, '@import'.length ) !== '@import';
                        }
 
                        /**