Mobile app version of vmapp.org
Login or Join
Gretchen104

: Leverage Browser Caching - third party resources I am optimising a website based on PageSpeed Insights guidelines. And one of the points is to Leverage Browser Caching. And in this case - for

@Gretchen104

Posted in: #Cache #GooglePagespeed

I am optimising a website based on PageSpeed Insights guidelines. And one of the points is to Leverage Browser Caching.


And in this case - for the third party resources - like Google Analytics and Tag Manager.

I already added this code to .htaccess file:

# Expires headers
<IfModule mod_expires.c>
ExpiresActive on

ExpiresDefault "access plus 2 days"

# cache.appcache needs re-requests in FF 3.6
ExpiresByType text/cache-manifest "access plus 0 seconds"

# Your document html
ExpiresByType text/html "access plus 0 seconds"

# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"

# Feed
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"

# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"

# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"

# HTC files
ExpiresByType text/x-component "access plus 1 month"

# Webfonts
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType application/x-font-woff2 "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"

</IfModule>


What should i add to this code? And what is the recommended period for browser caching for Google Analytics and Google Tag Manager?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Gretchen104

2 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

As @TimFountain says, you have "no control" over resources served from a third party. The request goes to the third party server, not your server - so any code you place on your server is simply never processed when the third party resource is requested.

Google Analytics and Tag Manager are served from Google's servers. Only Google controls Google's servers!

However, if Google has decided not to cache these resources then there may be a very good reason why it has chosen not to do so. Not everything should be cached.

Attempting to implement caching on these "Google" resources (perhaps by serving these resources from your own server instead - not recommended) - whilst satisfying the PageSpeed test - could have a negative effect on your user experience and Analytics data. The PageSpeed tool is a guide only. You shouldn't blindly accept the recommendations.

This question over on StatckOverflow specifically discusses Google Analytics and PageSpeed Insights:

stackoverflow.com/questions/29162881/pagespeed-insights-99-100-because-of-google-analytics-how-can-i-cache-ga

10% popularity Vote Up Vote Down


 

@Cooney921

Your htaccess rules will only affect assets served from your server. There is nothing you can do to affect caching of assets served from third party servers - you have no control over these.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme