2012-03-10 129 views
2

我使用来自Facebook的Like Box代码,我发现它阻碍了我的页面加载。在Firebug中查看后,它加载了一堆Javascript和CSS文件。我想知道是否有缓存Facebook Like框的方法?我确实搜索过Google,但我看到的只有一个是WordPress。我使用的是PHP。缓存Facebook Like Box?

回答

0

有一种方法可以做到这一点:使用频道文件并尽可能缓存它。了解更多关于它here

+1

你能详细说明如何实际编码吗?我迷失在SDK中。 – roadsunknown 2012-04-03 17:53:08

1

我用@马丁链接才能找到此链接https://developers.facebook.com/docs/reference/javascript/

下面的代码进行了修改,以适应我的情况,但我不知道它是如何更快的是,或者如果缓存正常工作。

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.php', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    // Additional initialization code here 
    }; 

    // Load the SDK Asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 
</script> 

我channel.php看起来是这样,也从同一个页面:

<?php 
$cache_expire = 60*60*24*365; 
header("Pragma: public"); 
header("Cache-Control: max-age=".$cache_expire); 
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT'); 
?> 
<script src="//connect.facebook.net/en_US/all.js"></script> 

希望帮助添加到解决方案。