Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leverage browser caching external files

I used google pagespeed Insights to test the performance of my nodejs website. For some of external files it is saying to leverage browser caching but I don't know how to do this ?

Leverage browser caching

Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network. Leverage browser caching for the following cacheable resources:

http://maps.googleapis.com/…kwPPoBErK_--SlHZI28k6jjYLyU&sensor=false (30 minutes)

http://www.google-analytics.com/analytics.js (2 hours)

Anyone please help me on this.

like image 422
Manoj Avatar asked Aug 25 '14 06:08

Manoj


1 Answers

One solution is to reverse proxy the Google resources. Then you can add Cache-Control and other caching headers. If you're using Apache you can accomplish it as follows in your httpd.conf file:

ProxyRemote http://www.google-analytics.com http://yourinternalproxy:yourport

<Location /analytics.js>
  ProxyPass http://www.google-analytics.com/analytics.js
  ProxyPassReverse http://www.google-analytics.com/analytics.js
  Header set Cache-Control "max-age=86400"
</Location>

The drawbacks of this are that:

  • You'll funnel a lot of additional traffic through your servers.
  • Obviously updates made by Google will take longer to appear for the user's of your site.
like image 153
rudolfv Avatar answered Oct 17 '22 23:10

rudolfv