gpt4 book ai didi

javascript - Google Plus 一键速度。鼠标悬停加载

转载 作者:太空狗 更新时间:2023-10-29 15:02:10 26 4
gpt4 key购买 nike

我想听听您对我遇到的问题和解决方案的看法google plus one button(以及任何其他社交小部件)。

我们有一个高流量网站,运行快速流畅(加载时间不到 1 秒)。在尝试实现 google plus 按钮时,我们发现加载时间变得荒谬。

Google 到处都在喋喋不休地谈论加载时间,但他们仍然制作一个缓慢的小部件?

我们需要社交小部件,但加载速度对我们的用户和 SEO 至关重要。

我想在网站加载后加载 google 按钮,这样用户就不会注意到任何速度差异,但仍然可以加上胡说八道。

我想听听这种方法的缺点,或者更好的解决方案。

使用 body 上的鼠标悬停事件来加载社交小部件。它有效,但我不确定这是否可以接受。

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>

请告诉我您的想法,或者我是否可以改进这个想法。

最佳答案

遇到过同样的问题,做了这样的事情:

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"});
});
}

函数在窗口加载后运行几毫秒。

关于javascript - Google Plus 一键速度。鼠标悬停加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8638376/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com