Google Pagespeed recommends caching resources for at least a week under "Leverage browser caching". I've done it for internal files but I was wondering if something could malfunction if I did the same to social media files:

  • http://connect.facebook.net/en_US/all.js (20 minutes)
  • http://platform.twitter.com/widgets.js (30 minutes)
  • https://apis.google.com/js/api.js (30 minutes)
  • https://apis.google.com/js/plusone.js (30 minutes)
  • https://www.gstatic.com/swiffy/v7.1.1/runtime.js (50 minutes)
  • http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js (60 minutes)
  • http://pagead2.googlesyndication.com/pagead/osd.js (60 minutes)
  • https://oauth.googleusercontent.com/…e:rpc:shindig.random:shindig.sha1.js?c=2 (60 minutes)
  • http://stats.g.doubleclick.net/dc.js (2 hours)

The numbers in parenthesis indicate current expiration time.

  • 2
    You wouldn't be able to increase the cache time unless you host those files within your control and that would be a bad idea since Google, Facebook, and Twitter do updates to those libraries, it could also be against their usage policy. Dec 8 '14 at 20:59
  • The plan is to automate the caching. Do you think the mentioned files require updates more frequent than once a week?
    – Renan
    Dec 8 '14 at 21:32
  • See Can .htaccess be used to cache AdSense JavaScript to improve the pagespeed score? which is basically the same question but for AdSense files Dec 10 '14 at 17:38

You can only control the caching of files from your own domain. Facebook, Google, and DoubleClick serve those files. If your server isn't the one that sends the files to users, you have no control over their caching. Facebook, Google, and DoubleClick have thought about caching times and have set them appropriately.

The page speed recommendations are just that: recommendations. They are not hard and fast rules. There are times that you want to break the rules. In this case, these third party providers don't allow those files to be cached very long for freshness.

If you want a perfect page speed score, you would have to stop using these third party services.


Yes, sure, something could malfunction, though probably it would be to hard to notice this unless you cache it for thousands of clients.

The cache expire time is set by every site for reason, according to their update deployment practices. If you override this, beware of malfunction.

Also, overriding cache expire time by any intermediate cache/proxy is a violation of HTTP standards (RFC7234 Section 4.2.4. Serving Stale Responses).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.