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

    5,451
    1,412
    113
    May 25, 2014
    Ratings:
    +2,206
    Local Time:
    3:22 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/ga-lite@2/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
     
  2. rdan

    rdan Well-Known Member

    5,451
    1,412
    113
    May 25, 2014
    Ratings:
    +2,206
    Local Time:
    3:22 AM
    Mainline
    10.2
    Lower down my Webpagetest Fully Loaded time from 4-5 seconds to 2-3 seconds (with Adsense).
     
  3. Jay Chen

    Jay Chen Active Member

    184
    60
    28
    Sep 10, 2017
    Ratings:
    +116
    Local Time:
    3:22 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.
     
  4. rdan

    rdan Well-Known Member

    5,451
    1,412
    113
    May 25, 2014
    Ratings:
    +2,206
    Local Time:
    3:22 AM
    Mainline
    10.2
    After using this for 43 days now, only issue I observe was not correct Site Speed stats.
     
  5. eva2000

    eva2000 Administrator Staff Member

    55,805
    12,272
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,858
    Local Time:
    5:22 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yeah very true :)

    How did you test/determine this ? Got an example ?
     
  6. rdan

    rdan Well-Known Member

    5,451
    1,412
    113
    May 25, 2014
    Ratings:
    +2,206
    Local Time:
    3:22 AM
    Mainline
    10.2
    Happens rarely maybe once a year or not as they use:
    upload_2019-12-16_11-38-42.png
     
  7. eva2000

    eva2000 Administrator Staff Member

    55,805
    12,272
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,858
    Local Time:
    5:22 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Offloading Google Analytics to be served on your own domain is to improve page load speed - so that is what I see from your GA stats. You can verify by also comparing Avg Dom Content Loaded and Avg Dom Interactive times in GA and Cloudflare Browser Insight stats for the domain over the same period.