Search code examples
optimizationcompressionfacebook-javascript-sdkhttp-compression

Enable compression on facebook sdk served files to optimize site


I was running page speed insights on my website and was given the following result:

Compressing resources with gzip or deflate can reduce the number of bytes sent over the network.

Enable compression for the following resources to reduce their transfer size by 350.1KiB (71% reduction).

Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yV/r/jchZvGuNSq4.js could save 230.8KiB (72% reduction).

Compressing http://connect.facebook.net/en_US/sdk.js could save 119.3KiB (69% reduction).

I am wondering if anyone knows how to compress these files since they are served out directly from the facebook sdk?

This is the facebook script I am using in my webpages:

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '---- my app ID here -----',
      xfbml      : true,
      version    : 'v2.4'
    });
  };
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

Any help would be greatly appreciated as I have been unable to find a clear answer to this identified problem.


Solution

  • I have also noticed this and went Googling and found your SO question. I did some checks and it looks like they already compress their static files. Have a look at this:

    http://www.whatsmyip.org/http-compression-test/

    EDIT: I recommend using https://checkgzipcompression.com/ now, the previously named test seems to have lost its functionality

    I'm not sure why Pagespeed Insights doesn't pick up on this, but I am pretty sure you can ignore this. Because you don't have much influence on the way they serve their static files and I would be suprised if they didn't compress their static files at a company like Facebook.