Reputation: 1333
I want to use Modernizr for my MediaWiki skin, but it appears that ResourceLoader only loads scripts at the bottom of the <body>
. Is there a way for me to load it in the <head>
?
Based on @Bergi's answer below, I created an extension with the 'top' position to get it to load in the head:
extensions/Modernizr/Modernizr.php
<?php
$wgResourceModules['ext.Modernizr.foo'] = array(
'scripts' => 'modules/modernizr-2.6.2.min.js',
'remoteExtPath' => 'Modernizr',
'position' => 'top'
);
The modernizr-2.6.2.min.js file is in the extensions/Modernizr/modules/ folder.
And load it as follows: LocalSettings.php
require_once( "$IP/extensions/Modernizr/Modernizr.php" );
In the execute()
function in my skin file:
global $wgOut;
$wgOut->addModules('ext.Modernizr.foo');
Is this the wrong place to call $wgOut->addModules()
?
Modernizr is still not being loaded or run.
Upvotes: 2
Views: 1436
Reputation: 664256
Yes, you can specify a position
parameter for scripts in the $wgResourceModules
definition. Set it to top
for modernizr and then load it via $wgOut->addModules
.
Upvotes: 1