Leverage browser caching

1,534 views
Skip to first unread message

a.s...@doc.ua

unread,
Feb 17, 2017, 6:10:05 AM2/17/17
to pagespeed-insights-discuss
Leverage browser caching for the following cacheable resources:

https://ssl.google-analytics.com/ga_exp.js?utmxkey=81624572-15&utmx=&utmxx=&utmxtime=1487167376402 (30 seconds)
https://maps.google.com/maps/api/js?key=AIzaSyDh5MkGZQcCxjMq8WIzDo6J9yhaPQFBtAQ (30 minutes)
https://www.google-analytics.com/analytics.js (2 hours)

How to Leverage browser caching for the following cacheable resources?

There are 15 static components without a far-future expiration date.
https://www.google-analytics.com/cx/api.js
https://maps.google.com/maps/api/js?key=AIzaSyDh5MkGZQcCxjMq8WIzDo6J9yhaPQFBtAQ
https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic&subset=latin,cyrillic
https://www.googleadservices.com/pagead/conversion.js
https://ssl.google-analytics.com/ga_exp.js?utmxkey=81624572-15&utmx=&utmxx=&utmxtime=1487167376402
https://www.google-analytics.com/analytics.js
https://maps.googleapis.com/maps/api/js/ViewportInfoService.GetViewportInfo?1m6&1m2&1d49.2857666015625&2d29.546630859375&2m2&1d51.58245849609375&2d31.47088623046875&2u9&4sen-US&5e0&6sm%40373000000&7b0&8e0&callback=_xdc_._3vo4hb&token=54821
https://maps.googleapis.com/maps/api/js/StaticMapService.GetMapImage?1m2&1i76531&2i43989&2e1&3u9&4m2&1u226&2u425&5m5&1e0&5sen-US&6sus&10b1&12b1&token=83948
https://fonts.googleapis.com/css?family=Roboto:300,400,500,700
https://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?1shttps%3A%2F%2Fdoc.ua%2Fdoctors%2Fkiev%2Fall%2Fginekolog&4sAIzaSyDh5MkGZQcCxjMq8WIzDo6J9yhaPQFBtAQ&callback=_xdc_._69mlug&token=16481


How to add expire headers for these resources?

André Böker

unread,
Feb 18, 2017, 2:56:23 AM2/18/17
to pagespeed-insights-discuss
host on your own server

a.s...@doc.ua

unread,
Feb 20, 2017, 1:51:14 AM2/20/17
to pagespeed-insights-discuss
How can I host on my server external resource? For example, analytics.js ?

André Böker

unread,
Feb 20, 2017, 2:12:47 PM2/20/17
to pagespeed-insights-discuss
you download it to your server and change the source for analytics.js in
the html head.
In this example you see we are loading ga.js from local source

<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','/uploads/scripts/ga.js','ga');
ga('create', 'UA-66591824-1', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>

Joshua Marantz

unread,
Feb 20, 2017, 5:51:54 PM2/20/17
to pagespeed-insights-discuss
I don't think this is a good idea.  The GA team may decide to roll out a JS change along with a server-side change with an expectation that no one will reference the old JS one hour after they roll it out.  The server-side change might be compatible with the old JS only for 1 hour (or whatever it is cached for).  Then they can roll out the server-side changes that require the new JS.  If you host on your own server, your code could break at any time.

Moreover, there is a lot of inter-site cacheability that you are giving up.  PSI doesn't really credit you for this, but popular scripts loaded on site A will benefit site B if they are served from their origin.

One solution that *does* actually respect the origin TTL, at least, is mod_pagespeed's MapProxyDomain.  However, I don't recommend proxying analytics.js because of the inter-side cacheability loss.  But at least it doesn't suffer from the correctness issues of manually copying the script to your own server.




--
You received this message because you are subscribed to the Google Groups "pagespeed-insights-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pagespeed-insights-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pagespeed-insights-discuss/7086bb70-07a2-4f59-8d60-84529ac8722d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

André Böker

unread,
Feb 20, 2017, 7:10:43 PM2/20/17
to pagespeed-insights-discuss
We are not affraid of changes as we use a cronjob to update our sourcefile frequently. 
I just want to show a solution because a lot of people are complaining about pagespeed insights showing this as a mistake. 

Whenever the ga.js or analytics.js is changed they only add new functionalities.The file should be backwards compatible as you can check here . 
and here

We will do whatever it takes to keep Pagespeed 100/100. We believe this is important and an unfair advantage for us. xD
Reply all
Reply to author
Forward
0 new messages