Reputation: 6220
I am trying to load some of my scripts from CDNs like CDNjs and Google, The scripts are being loaded correctly, but for some reason I do not find, for each script I have two or even three HTTP request (For the same script), here is an example: http://tools.pingdom.com/fpt/#!/ePuR3Z/http://elbauldelprogramador.com.
I have notice that when I am logged in, all scripts are generating only one HTTP request.
Jquery from ajax.googleapis is generating two http request, and jquery.easing.min.js from cdnjs three.
The code is :
//Making jQuery Google API
function modify_jquery() {
if (!is_admin()) {
// comment out the next two lines to load the local copy of jQuery
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js', false, '2.0.3');
wp_enqueue_script('jquery');
}
}
add_action('init','modify_jquery');
I have a child theme and from his parent I have copied a function called wi_enqueue(). In the parent the function is like this:
add_action( 'wp_enqueue_scripts', 'wi_enqueue' );
if ( !function_exists('wi_enqueue') ) {
function wi_enqueue(){
/* ...*/
}
In my child function.php I have:
function wi_enqueue(){
global $wp_styles, $smof_data;
/* Enqueue */
wp_enqueue_script( 'wi-easing', '//cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js', array('jquery'), '1.3', true );
wp_enqueue_script( 'wi-touchswipe', '//cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.4/jquery.touchSwipe.min.js', array('jquery'), '1.3.3', true );
wp_enqueue_script( 'wi-autosize', '//cdnjs.cloudflare.com/ajax/libs/autosize.js/1.17.1/autosize-min.js', array('jquery'), '1.17.1', true );
wp_enqueue_script( 'wi-placeholder', '//cdnjs.cloudflare.com/ajax/libs/placeholders/2.1.0/placeholders.min.js', array('jquery'), '2.1.0', true );
wp_enqueue_script( 'wi-modernizr', get_template_directory_uri() . '/js/modernizr.custom.15463.js', array('jquery'), '2.6.2', true );
wp_enqueue_script( 'wi-waypoint', '//cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.2/waypoints.min.js', array('jquery'), '2.0.2', true );
wp_enqueue_script( 'wi-tipsy', get_template_directory_uri() . '/js/jquery.tipsy.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'wi-fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), '1.0', true );
wp_enqueue_script( 'wi-sidr', get_template_directory_uri() . '/js/jquery.sidr.min.js', array('jquery'), '1.1.1', true );
/* .... */
}
Upvotes: 4
Views: 1083
Reputation: 1
If scripts are being loaded more than once, review your source code and save it once again. Then you might want to clear your browser cache to make sure that the previous cache is cleared so you can view the current updated website. If you still have the same problem it might be because of your template or wordpress not properly installed/configured.
Thus, I do highly recommend you to post a thread on wordpress.org instead if you still face the same problem. Hope this helps.
Upvotes: 0
Reputation: 2408
This may or may not resolve your question, but I had a very similar issue a while ago and spent a long time pulling my hair out looking for a solution. In the end it turned out that some browsers (Firefox being the most common of the guilty ones) prefetch the next post/article, including JS and other page elements, based on the <link rel="next" />
tag.
There's a lot more information on this here: http://www.ebrueggeman.com/blog/wordpress-relnext-and-firefox-prefetching
Hopefully this will help, if you're still having the issue.
Upvotes: 1