Welcome to Centmin Mod Community
Become a Member

WebPerf How to Fix Google Analytics Leverage Browser Caching Warning?

Discussion in 'Web Development & Web Performance' started by rdan, Nov 3, 2019.

  1. rdan

    rdan Well-Known Member

    4,715
    1,138
    113
    May 25, 2014
    Ratings:
    +1,694
    Local Time:
    5:02 AM
    Mainline
    10.2
    Use ga-lite, which is a small, cacheable subset of Google Analytics JS client, created by Jesse Luoto. Note that this uses an API that is actually supported by Google.

    You can install ga-lite to your project by adding the following code to the ended of your HTML <body>. You can download the file locally to your server or your own CDN as well.

    Code:
    <script>
    (function(e,t,n,i,s,a,c){e[n]=e[n]||function(){(e[n].q=e[n].q||[]).push(arguments)}
    ;a=t.createElement(i);c=t.getElementsByTagName(i)[0];a.async=true;a.src=s
    ;c.parentNode.insertBefore(a,c)
    })(window,document,"galite","script","https://cdn.jsdelivr.net/npm/[email protected]/dist/ga-lite.min.js");
    
    galite('create', 'UA-XXXXXXXX-X', 'auto');
    galite('send', 'pageview');
    </script>
    This includes the most recent version of ga-lite to your site and initializes the script with your own UA code. See more documentation on GitHub.

    Fix Leverage Browser Caching Warning - KeyCDN
     
    • Informative Informative x 3
  2. rdan

    rdan Well-Known Member

    4,715
    1,138
    113
    May 25, 2014
    Ratings:
    +1,694
    Local Time:
    5:02 AM
    Mainline
    10.2
    Lower down my Webpagetest Fully Loaded time from 4-5 seconds to 2-3 seconds (with Adsense).
     
    • Like Like x 2
  3. Jay Chen

    Jay Chen Active Member

    106
    33
    28
    Sep 10, 2017
    Ratings:
    +57
    Local Time:
    4:02 PM
    This is great, the only downside is whenever GA APIs get updated or deprecated, you will have to wait for the developer to release the new version with the updated APIs.