0

Facebook SDK is the most heavy file of all my website. It require about 5sec to load.

enter image description here

This is because Cache-control is set to 389sec. Do know a way to extend it to at least a week? Could be a good practice to insert all.js into my "asset pipeline" and set cache expire by fingerprint?

enter image description here

FacebookSDK.js.coffee

initializeFacebookSDK = ->
  FB.init
    channelUrl   : '//website.herokuapp.com/page/fbchannel'
    cookie       : true
    xfbml        : true
    status       : false
    oauth        : false

PageController

class PageController < ApplicationController

def fbchannel
    cache_expire = 1.year
    response.headers["Pragma"] = "public"
    response.headers["Cache-Control"] = "max-age=#{cache_expire.to_i}"
    response.headers["Expires"] = (Time.now + cache_expire).strftime("%d %m %Y %H:%I:%S %Z")
    render :layout => false, :inline => "<script src='//connect.facebook.net/it_IT/all.js'></script>"
  end
end
sparkle
  • 7,530
  • 22
  • 69
  • 131
  • all.js supports ETags, so even if the resource expires locally, the ETag should keep it from having to be loaded again. That said, the expiration should not be as short as 6 minutes. Are you sure you have no proxies that are changing the headers? – Sean Kinsey Jul 30 '13 at 05:01
  • I'm using Mobile Tethering wifi. This could be the reason? – sparkle Jul 30 '13 at 06:55

0 Answers0