首页 > 实用技巧 > 给页面添加Google+1按钮的方法【附代码】

给页面添加Google+1按钮的方法【附代码】

Google +1在网站SEO中应该会期待一定的作用,在未来可能会发挥更大的作用。

在网页中添加Google +1代码其实很简单的,如下几句话就可以轻松搞定了:

<!– Place this tag in your head or just before your close body tag –>
<script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script>
<!– Place this tag where you want the +1 button to render –>
<g:plusone></g:plusone>

不过问题也随之而来了,部署上以后发现网站打开速度变慢了,Google +1按钮总要等上数秒甚至是数十秒才能读取完毕出现在页面里。

那怎么办?如何取舍?一定要将其拿掉吗?

不是的,有人给出了优化的办法,可以加快Google +1的加载速度。代码如下:

<!– Place this tag just before your close body tag –>
<script>
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = ‘https://apis.google.com/js/plusone.js’;
s.parentNode.insertBefore(g, s);
})(document, ‘script’);
</script>
<!– Place this tag where you want the +1 button to render –>
<g:plusone></g:plusone>





实用技巧->, ,

发表评论

无觅相关文章插件,快速提升流量