Many modules, extensions or other things in Yii try to load jQuery from the asset manager. Which is fine, I’ve quit hardcoding the include and instead I am embracing ‘registerCoreScript’.
The only issue is that it seems to be loading it near the bottom of the HEAD. I have a lot of other scripts and code that depend on jQuery, and they are loaded before it. How do I make sure that jQuery is the first thing loaded??
The truth is I don’t understand how it’s not the default behavior. jQuery doesn’t depend on anything, but lots of scripts depend on it…
You can use
packagesproperty of CClientScript component, and specifydepends:Or do it this in config/main.php configuration:
And then use
registerPackage:This is the only way that this can be done, i think. Of course this requires you to either group your javascript into a package and give it some name, or declare each script as a package.
Related answers: this and this