谷歌加一键速度。鼠标悬停时加载

发布于 2024-12-23 07:10:05 字数 1190 浏览 1 评论 0原文

我想了解您对我遇到的问题和解决方案的意见 谷歌加一按钮(以及任何其他社交小部件)。

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

谷歌到处都在谈论加载时间,但他们仍然制作一个缓慢的小部件?

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

我想在网站加载后加载谷歌按钮,这样用户就不会注意到任何速度差异,但仍然有能力对我们说废话。

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

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

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>

请让我知道您的想法或者我是否可以改进这个想法。

I would like your opinion about an issue and solution i have with
google plus one button ( and any other social widget ).

We have a high traffic site , that runs fast and smoothly ( under 1 seconds load time ).
When trying to implement the google plus button we saw our load time grow to absurdity.

Google is blabbing about load times all around and they still make a slow widget ?

We need the social widgets , but the load speed is crucial for our users and SEO.

I was thinking to load the google button after the site was loaded so users would not notice any speed difference , but still had the ability to plus bullshit us.

I would like to hear the cons for this approach, or maybe even a better solution.

Using the mouseover event on the body to load the social widgets.
It works , but I am not sure if this is acceptable.

http://www.webpagetest.org shows the same speed as before the button implementations.

Using 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>

Please let me know what you think or if I could improve this idea.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

决绝 2024-12-30 07:10:05

遇到过同样的问题,并做了类似的事情:

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

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

Have experienced the same problems, and did something like this:

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

Function runs a few milliseconds after the window is loaded.

三生殊途 2024-12-30 07:10:05

除了 onLoad 之外,还有一个简单的替代方法 - 您可以在容器的悬停事件上执行此操作。好处是加载不会显得很慢,并且您可以使用自己设计的按钮来适应页面的设计。对于那些不关心它们的人来说,它也不会加载。它甚至可以为您提供额外的分析信息。不利的一面是,从悬停到加载,您仍然有相同的加载时间。人们可能会担心悬停后加载所需的时间足以阻止他们点击。

Techcrunch 在他们的主页上做了类似的事情,尽管他们是在整个新闻项目的容器上做的。请注意,他们的网站无论如何都非常慢。

There is a slight alternative to doing it onLoad - you could do it on a hover event of the container. The upside is it won't appear slow to load and you can have buttons of your own design to fit in to the page's design. It also won't load for people who aren't bothered about them. It could even give you extra analytical information. The down side is that from the hover to load you still have that same loading time. One would worry that the time it takes for those to load after the hover is enough to put them off clicking.

Techcrunch do a similar thing on their home page, though they do it on the container of the whole news item. Mind you, their site is awfully slow anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文