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.
我试图从CDNs加载我的一些脚本,如CDNjs和谷歌,脚本正确加载,但由于某种原因,我没有找到,对于每个脚本我有两个甚至三个HTTP请求(对于相同的脚本),这是一个例子: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.
我注意到,当我登录时,所有脚本只生成一个HTTP请求。
Jquery from ajax.googleapis is generating two http request, and jquery.easing.min.js from cdnjs three.
来自ajax.googleapis的Jquery正在生成两个http请求,并从cdnjs生成jquery.easing.min.js三个。
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:
我有一个子主题,从他的父母我复制了一个名为wi_enqueue()的函数。在父级中,函数是这样的:
add_action( 'wp_enqueue_scripts', 'wi_enqueue' );
if ( !function_exists('wi_enqueue') ) {
function wi_enqueue(){
/* ...*/
}
In my child function.php I have:
在我的孩子function.php我有:
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 );
/* .... */
}
2 个解决方案
#1
1
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.
这可能会或可能不会解决您的问题,但我前一段时间有一个非常类似的问题,并花了很长时间来寻找解决方案。最后,事实证明,某些浏览器(Firefox是最常见的有害浏览器)根据 标签预取下一篇文章/文章,包括JS和其他页面元素。
There's a lot more information on this here: http://www.ebrueggeman.com/blog/wordpress-relnext-and-firefox-prefetching
这里有更多相关信息:http://www.ebrueggeman.com/blog/wordpress-relnext-and-firefox-prefetching
Hopefully this will help, if you're still having the issue.
如果你还有这个问题,希望这会有所帮助。
#2
0
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.
如果多次加载脚本,请查看源代码并再次保存。然后,您可能希望清除浏览器缓存以确保清除先前的缓存,以便查看当前更新的网站。如果您仍然遇到相同的问题,可能是因为您的模板或wordpress没有正确安装/配置。
Thus, I do highly recommend you to post a thread on wordpress.org instead if you still face the same problem. Hope this helps.
因此,我强烈建议您在wordpress.org上发布一个帖子,如果您仍然面临同样的问题。希望这可以帮助。
#1
1
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.
这可能会或可能不会解决您的问题,但我前一段时间有一个非常类似的问题,并花了很长时间来寻找解决方案。最后,事实证明,某些浏览器(Firefox是最常见的有害浏览器)根据 标签预取下一篇文章/文章,包括JS和其他页面元素。
There's a lot more information on this here: http://www.ebrueggeman.com/blog/wordpress-relnext-and-firefox-prefetching
这里有更多相关信息:http://www.ebrueggeman.com/blog/wordpress-relnext-and-firefox-prefetching
Hopefully this will help, if you're still having the issue.
如果你还有这个问题,希望这会有所帮助。
#2
0
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.
如果多次加载脚本,请查看源代码并再次保存。然后,您可能希望清除浏览器缓存以确保清除先前的缓存,以便查看当前更新的网站。如果您仍然遇到相同的问题,可能是因为您的模板或wordpress没有正确安装/配置。
Thus, I do highly recommend you to post a thread on wordpress.org instead if you still face the same problem. Hope this helps.
因此,我强烈建议您在wordpress.org上发布一个帖子,如果您仍然面临同样的问题。希望这可以帮助。