Want to subscribe to topics you're interested in?
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,802
    1,153
    113
    May 25, 2014
    Ratings:
    +1,728
    Local Time:
    7:37 PM
    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,802
    1,153
    113
    May 25, 2014
    Ratings:
    +1,728
    Local Time:
    7:37 PM
    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

    117
    36
    28
    Sep 10, 2017
    Ratings:
    +62
    Local Time:
    6:37 AM
    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

    4,802
    1,153
    113
    May 25, 2014
    Ratings:
    +1,728
    Local Time:
    7:37 PM
    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

    42,833
    9,705
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,970
    Local Time:
    9:37 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Yeah very true :)

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

    rdan Well-Known Member

    4,802
    1,153
    113
    May 25, 2014
    Ratings:
    +1,728
    Local Time:
    7:37 PM
    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

    42,833
    9,705
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,970
    Local Time:
    9:37 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    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.
     
    • Like Like x 1