Fix Leverage Browser Caching Warning for Google Analytics in WordPress

JavaScript for WordPress

It’s very common to get this warning when you run speed tests for your WordPress website:

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:

Leverage browser caching for the following cacheable resources:

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

Leverage Browser Caching

This error is referring to Google Analytics “analytics.js” file. And as it a 3rd party script, you cannot add expires headers to your .htaccess file or your Nginx configuration file.

How to fix for your WordPress?

Generally, you can fix this issue or any similar one by hosting the script locally on your server. But this particular script needs to be updated regularly when Google updates it. So you can host the script and run a cron job to update it.

Fortunately, there is a lightweight plugin that does everything for you, just install, configure and forget about the Google Analytics Leverage Browser Caching warning.

banner-772x250

Complete Analytics Optimization Suite (CAOS) is a plugin that inserts the Analytics tracking code into the header or footer, saves the analytics.js file locally and keeps it updated using wp_cron().

When you install Complete Analytics Optimization Suite (CAOS), go to Settings -> Optimize Analytics

Complete Analytics Optimization Suite

Enter in your Google Analytics Tracking ID and position for your tracking code. That’s all!

Now test your newly added tracking code by visiting your website in a new incognito window (Google Chrome) or Private window (Firefox) by going to your Google Analytics account -> Real Time -> Overview.

Please note:

You will need to deactivate other Google Analytics plugins or remove any other Google Analytics tracking codes you added to avoid inaccurate reporting.

Conclusion

Complete Analytics Optimization Suite (CAOS) is a cool plugin that helps you to add the Google Analytics code wherever you want (in the footer for example) and also get rid of the Leverage Browser Caching warning in your website speed tests.

GET MORE STUFF 
IN YOUR INBOX
WordPress Multilingual, Performance, SEO, Reviews and HOT Deals. One email per week!
Stay Updated
Give it a try, you can unsubscribe anytime.
Close
GET MORE STUFF
IN YOUR INBOX
WordPress Multilingual, Performance, SEO, Reviews and HOT Deals. One email per week!
Stay Updated
Give it a try, you can unsubscribe anytime.
We have created the 1st online directory for the Multilingual Themes
CLICK HERE

WE'RE SOCIAL!

Follow us on..