Last modified: 2014-02-18 21:30:16 UTC
I noticed that when I enable this gadget https://test.wikipedia.org/wiki/Special:Gadgets/export/EditTools and go to https://test.wikipedia.org/w/index.php?title=TestPage&action=edit&debug=1 the HTML source code of the page contains two copies of https://test.wikipedia.org/w/index.php?title=MediaWiki:Gadget-EditTools.css&oldid=144099 Indeed, searching for elements containing "ext.gadget.EditTools&only=styles" on Google Chrome 21.0.1180.89 I find: <link rel="stylesheet" href="//test.wikipedia.org/w/load.php?debug=true&lang=en&modules=ext.gadget.EditTools&only=styles&skin=vector&*"> and <link type="text/css" rel="stylesheet" href="//test.wikipedia.org/w/load.php?debug=true&lang=en&modules=ext.gadget.EditTools&only=styles&skin=vector&version=20120916T155758Z&*"> The same happens for "ext.gadget.hlist-test&only=styles": <link rel="stylesheet" href="//test.wikipedia.org/w/load.php?debug=true&lang=en&modules=ext.gadget.hlist-test&only=styles&skin=vector&*"> <link type="text/css" rel="stylesheet" href="//test.wikipedia.org/w/load.php?debug=true&lang=en&modules=ext.gadget.hlist-test&only=styles&skin=vector&version=20120916T155758Z&*">
This was also brought up in bug 29693 comment 9, see my response there for an explanation of why this is currently happening.
I was going to duplicate with bug 29693. Whatever solution (if any) is considered, it can be applied to Gadgets similarly. One possible way (though not an option for gadget) is to require that modules be split in a part that contains style for server output and a module with javascript and styling for that. That's how we do it in core for some of these cases. Note that this split up can not (should not) be automated because some stylesheets are only relevant in a scripted context and visa versa. The only problem is that we don't have a way to tell gadgets that it should be loaded as a <link> only with only=styles. Effectively adding a new type of module (dynamic bottom, dynamic top, static top), which can't have scripts.
This double loading is going to occur with gadgets and the 'mediawiki.ui.button' module. We recommend gadgets explicitly load their required modules; we will probably add addModuleStyles( 'mediawiki.ui.button' ) on all pages so that simple templates like {{Blue button}} work without JavaScript. So the button CSS will be added to a style tag in the DOM by the former and added as a link by the latter. The fix could be to add a separate mw.loader.loadCSS/usingCSS() function that can check to see if the CSS has already been loaded using addModuleStyles.