像Box一样缓存Facebook?

时间:2012-03-10 16:54:59

标签: facebook caching facebook-like

我正在使用Facebook的Like Box代码,我注意到它阻碍了我的页面加载。在查看Firebug后,它会加载一堆Javascript和CSS文件。我想知道有没有办法缓存Facebook Like框?我确实在搜索Google,但我看到的唯一一个是Wordpress。我正在使用php。

2 个答案:

答案 0 :(得分:1)

我使用@Martin链接查找此链接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>

希望有助于添加解决方案。

答案 1 :(得分:0)

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

相关问题