如何避免“像Facebook”按钮延迟网站上的加载? [英] How do I keep the Facebook like button from delaying the loading on my website?

查看:67
本文介绍了如何避免“像Facebook”按钮延迟网站上的加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将facebook like按钮添加到我的网站。加载下面的jscript会有一个延迟,直到完成该页面的其余部分才加载。另外,如果我用防火墙阻止了facebook,则放弃之前会有很长的延迟,然后显示页面的其余部分。如何先显示页面,然后显示类似按钮? (我这样做是为了看看如果Facebook有问题会怎样。)此外,当我加载不同的页面时,类似facebook的按钮会继续重新加载(直到重新加载-1/3秒才可见)。按钮位于同一位置在每一页上的顶部横幅中。其他图像不会重新加载-它们会被缓存-选择其他页面时它们会显示为静态。有什么方法可以缓存该脚本?

I have added the facebook like button to my website. There's a delay when the jscript below is loaded, and the rest of the page doesn't load until it's done. Also, if I block facebook with my firewall there's a very long delay before it gives up, and THEN the rest of my page is displayed. How do I get my page displayed first, and then that like button? (I did that to see what would happen if facebook was having a problem.) Also, when I load different pages the facebook like button keeps reloading (it's visibly absent until reloaded - 1/3 second.) The button is in the same place on every page, in a banner on top. The other images don't reload - they are cached - and they appear static when selecting a different page. Is there a way I can make that script be cached?

这里是代码:

<div style="position: absolute; top:20px; right:85px; width:70px; height:25px">
    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
    <fb:like href="http://www.facebook.com/pages/somepage/somenum" layout="box_count" show_faces="false" width="50"></fb:like>
</div>

谢谢

更新:
我找到了用于异步加载all.js的代码:

UPDATE: I found this code for loading all.js asynchronously:

另一种方法是异步加载,因此它不会阻止加载页面的其他元素:

"Another way is to load asynchronously so it does not block loading other elements of your page: "

<div id="fb-root"></div><script>window.fbAsyncInit = function() {  
FB.init({appId: 'your app id', status: true, cookie: true,  
xfbml: true});  
};  
(function() {  
var e = document.createElement('script'); e.async = true;  
e.src = document.location.protocol +  
'//connect.facebook.net/en_US/all.js';  
document.getElementById('fb-root').appendChild(e);  
}());  
</script>  

但是您的应用ID是什么?该代码是从此处 http://www.mohammedarif.com/?p=180

But what is "your app id?" That code is from here http://www.mohammedarif.com/?p=180

推荐答案

您可以按照问题更新中所述的方式异步加载。您可以从Facebook上的创建应用程序获取应用程序ID。 (谷歌浏览器...)

You can load asynchronously as I described in the update to the question. You get an app id from "create application" on facebook. (Google it...)

这篇关于如何避免“像Facebook”按钮延迟网站上的加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆