0

I have already leveraged cache files for common file types. But couldn't get much help on how to add cache expiration for 3rd party API like (Google API) and widgets like (Disqus, AddThis, Pinterest, Twitter) which are slowing my site to 80% (earlier it was 97%)

These are some of the common widgets which are slowing down my site:

  1. cdn.viglink.com/images/pixel.gif?ch=1&rn=5.711541143245995 (15 seconds)
  2. cdn.viglink.com/images/pixel.gif?ch=2&rn=5.711541143245995 (15 seconds)
  3. disqus.com/next/config.js (60 seconds)
  4. assets.pinterest.com/js/pinit_main.js?0.7067068491596729 (4 minutes)
  5. s7.addthis.com/js/300/addthis_widget.js (10 minutes)
  6. m.addthisedge.com/live/boost/ra-9a7a0e60b8044af/_ate.track.config_resp (60 seconds)
  7. platform.twitter.com/widgets.js (30 minutes)
  8. apis.google.com/js/api.js (30 minutes)
  9. apis.google.com/js/rpc:shindig_random.js?onload=init (30 minutes)

This is my .htaccess file

# Leverage Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access 1 year"
  ExpiresByType image/jpeg "access 1 year"
  ExpiresByType image/gif "access 1 year"
  ExpiresByType image/png "access 1 year"
  ExpiresByType text/css "access 1 month"
  ExpiresByType text/html "access 1 month"
  ExpiresByType application/pdf "access 1 month"
  ExpiresByType text/x-javascript "access 1 month"
  ExpiresByType text/javascript "access 1 month"
  ExpiresByType application/x-shockwave-flash "access 1 month"
  ExpiresByType image/x-icon "access 1 year"
  ExpiresDefault "access 1 month"
</IfModule>

<IfModule mod_headers.c>
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  </filesmatch>
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  </filesmatch>
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  </filesmatch>
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"
  </filesmatch>
</IfModule>
Rohit Sharma
  • 1,271
  • 5
  • 19
  • 37

1 Answers1

0

For setting cache expiration for Google Analytics (js) this is a good resource: Leverage browser caching for 3rd party JS

For others download all the js and place them locally on the server.

But I found a more simpler way to do it if you have got cloudflare (https installed)

Login to your cloudflare account and go to caching tab and set the Browser Cache Expiration level to a minimum 8 days and you are almost done just Purge everything and wait for 5 minutes and try testing your url in

https://developers.google.com/speed/pagespeed/insights/

If still your speed isn't accelerated then try bitly services for some long url for testing and see, mobile speed will definitely accelerate.

Rohit Sharma
  • 1,271
  • 5
  • 19
  • 37