Pao*_*der 6 html javascript seo jquery google-plus-one
我希望您对谷歌加一个按钮(以及任何其他社交小部件)的问题和解决方案有所了解.
我们有一个高流量站点,运行快速,流畅(加载时间不到1秒).在尝试实施google plus按钮时,我们看到我们的加载时间变得荒谬.
谷歌正在喋喋不休地谈论加载时间,他们仍然制作一个缓慢的小部件?
我们需要社交小部件,但加载速度对我们的用户和SEO至关重要.
我想在网站加载后加载谷歌按钮,这样用户就不会注意到任何速度差异,但仍然有能力加上废话我们.
我想听听这种方法的缺点,或者甚至是更好的解决方案.
在body上使用mouseover事件加载社交窗口小部件.它有效,但我不确定这是否可以接受.
http://www.webpagetest.org 显示与按钮实现之前相同的速度.
使用jquery:
<div id="testcase"></div>
<script type="text/javascript">
$(document).ready(function() {
$('body').mouseover(function() {
$('body').unbind();
// google html
$('#testcase').html('<g:plusone size="medium" annotation="inline"></g:plusone>');
// Google code
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
请让我知道您的想法或我是否可以改进这个想法.
遇到过同样的问题,并做了类似的事情:
function loadPlusOne() {
$.getScript("https://apis.google.com/js/plusone.js", function () {
gapi.plusone.render ("plusdiv", {"size": "medium", "count": "true", "expandTo": "top", "href": "http://mysite.com"});
});
}
Run Code Online (Sandbox Code Playgroud)
加载窗口后,函数运行几毫秒.