0

用 YSlow 测量它给我的页面一个 F 级,因为它发出了太多的 HTTP 请求。将我所有的 javascript 合并到一个文件中会减少 HTTP 请求,但在这种情况下可能吗?我想让我的页面加载得更快,所以我想知道在技术上是否可以将所有内容组合到一个 javascript 文件中,或者我是否处于无法进一步简化组件的位置:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '164355773607006', // App ID
      channelURL : '//WWW.KOOLBUSINESS.COM/static/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script><script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=adsense"></script>
<script type="text/javascript" src="static/js/home.js"></script>
4

1 回答 1

1

有可能将所有 javascript 文件合并到服务器端的一个文件中。但我认为这不会有很大的改善。

适当地使用 Cache-Control 标头以允许缓存和代理更有效地检索数据会更有效。

于 2011-10-31T07:34:13.943 回答