Change JS ordering

- Load jQuery before Modernizr so that the fallback method will
always be applied immediately after jQuery. If a script is
enqueued in the footer after jQuery, then the fallback shows up
in the footer. Modernizr will always be in the head so this
issue won't occur.

- Move plugins.js and main.js to footer

jQuery is still kept in the head to avoid conflicts with plugins
This commit is contained in:
Ben Word
2013-02-05 16:10:19 -06:00
parent eb9f9896a4
commit 6354758ad4
2 changed files with 13 additions and 13 deletions

View File

@@ -87,12 +87,12 @@ If you're using LESS, make sure you compile the files to the proper locations:
JavaScript is loaded in the following order:
1. `/theme/assets/js/vendor/modernizr-2.6.2.min.js`
2. `jquery-1.9.0.min.js` via Google CDN with local fallback
3. `/theme/assets/js/plugins.js`
4. `/theme/assets/js/main.js`
1. `jquery-1.9.0.min.js` via Google CDN with local fallback
2. `/theme/assets/js/vendor/modernizr-2.6.2.min.js`
3. `/theme/assets/js/plugins.js` (in footer)
4. `/theme/assets/js/main.js` (in footer)
jQuery is loaded in `head.php` using the same method from HTML5 Boilerplate: grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline. It's kept in the header instead of footer to avoid conflicts with plugins.
jQuery is loaded using the same method from HTML5 Boilerplate: grab Google CDN's jQuery, with a protocol relative URL; fallback to local if offline. It's kept in the header instead of footer to avoid conflicts with plugins.
`plugins.js` contains a minified version of all the latest Bootstrap plugins.

View File

@@ -9,10 +9,10 @@
* 4. /child-theme/style.css (if a child theme is activated)
*
* Enqueue scripts in the following order:
* 1. /theme/assets/js/vendor/modernizr-2.6.2.min.js
* 2. jquery-1.9.0.min.js via Google CDN
* 3. /theme/assets/js/plugins.js
* 4. /theme/assets/js/main.js
* 1. jquery-1.9.0.min.js via Google CDN
* 2. /theme/assets/js/vendor/modernizr-2.6.2.min.js
* 3. /theme/assets/js/plugins.js (in footer)
* 4. /theme/assets/js/main.js (in footer)
*/
function roots_scripts() {
@@ -30,7 +30,7 @@ function roots_scripts() {
// It's kept in the header instead of footer to avoid conflicts with plugins.
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', array('modernizr'), null, false);
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', false, null, false);
}
if (is_single() && comments_open() && get_option('thread_comments')) {
@@ -38,10 +38,10 @@ function roots_scripts() {
}
wp_register_script('modernizr', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.6.2.min.js', false, null, false);
wp_register_script('roots_plugins', get_template_directory_uri() . '/assets/js/plugins.js', false, null, false);
wp_register_script('roots_main', get_template_directory_uri() . '/assets/js/main.js', false, null, false);
wp_enqueue_script('modernizr');
wp_register_script('roots_plugins', get_template_directory_uri() . '/assets/js/plugins.js', false, null, true);
wp_register_script('roots_main', get_template_directory_uri() . '/assets/js/main.js', false, null, true);
wp_enqueue_script('jquery');
wp_enqueue_script('modernizr');
wp_enqueue_script('roots_plugins');
wp_enqueue_script('roots_main');
}