1

Site running Google Cloud CDN - According to numerous test is not Caching webp images - potentially all images.

This was corroborated with GTMetrix.

Initially, I used the Cloud CDN configuration of "Cache Static Content". and later upgraded to "Use origin settings based on cache-control headers" Current Cache Settings:

I am still seeing images, particularly webp not being cached by CDN. I have also updated the .htaccess file to increase the TTL for webp.

Htaccess images TTL

How can I get these images cached properly in cloud CDN?

GlennB
  • 48
  • 10

2 Answers2

1

That GTmetrix report is simply wrong. They apparently don't correctly detect use of Cloud CDN. I see cache hits from Cloud CDN for images such as /images/banner.webp.

There's information on troubleshooting cache misses at https://cloud.google.com/cdn/docs/troubleshooting-steps#responses-not-cached that you can use to double check.

elving
  • 1,441
  • 8
  • 7
  • Thank you @elving I appreciate the information. I'm still some-what confused as I don't appear to be able to fully change the TTL/cache-control using htaccess since setting up the CDN. It seems to have a cache, just not for very long – GlennB Mar 01 '21 at 11:17
  • @GlennB, that sounds right. Cache-Control max-age specifies the maximum amount of time an entry can remain in cache. It doesn't specify the *minimum* amount of time. If an entry is frequently accessed, it will typically remain in cache up to the max-age. If it's accessed infrequently, say less than once per day or so, it will be evicted to make room for more popular content. – elving Mar 02 '21 at 08:49
1

Just adding to elving's answer - the report is wrong - your site is using CDN for images too.

I've fallowed official documentation on troubleshooting GCP's CDN.

Just run curl -s -D - -o /dev/null https://mydoginsurance.com.au/images/banner.webp and you should get:

HTTP/2 200
server: nginx
date: Thu, 25 Feb 2021 12:26:01 GMT
content-type: image/webp
content-length: 130564
last-modified: Fri, 16 Oct 2020 10:12:50 GMT
etag: "5f897222-1fe04"
x-powered-by: PleskLin
accept-ranges: bytes
via: 1.1 google
cache-control: max-age=86400,public
alt-svc: clear

and when I ran it again a few minutes later:

HTTP/2 200
server: nginx
date: Thu, 25 Feb 2021 12:26:01 GMT
content-type: image/webp
content-length: 130564
last-modified: Fri, 16 Oct 2020 10:12:50 GMT
etag: "5f897222-1fe04"
x-powered-by: PleskLin
accept-ranges: bytes
via: 1.1 google
age: 223
cache-control: max-age=86400,public
alt-svc: clear

Third last line is age: 223 which means that this reponse was served from cache created 223 seconds ago;

The last response in this example includes an Age header. Cloud CDN adds an Age header to responses that it serves from cache. Here, the header indicates that the response was successfully served from cache by using a cache entry that was created two seconds ago.

Wojtek_B
  • 4,245
  • 1
  • 7
  • 21
  • Wow - thanks so much for checking this out for me; its super helpful. Its very strange that I'm still getting reports (gtmetrix and others such as web-page test that are saying I'm getting 50minute cache for the images, yet other assets are caching correctly... here is a competitor to GtMetrix [web page test]:(https://www.webpagetest.org/performance_optimization.php?test=210224_Di86_08b3576bc6f76c8d26d2d6fd4e121d04&run=1#cache_static_content) – GlennB Mar 01 '21 at 11:08
  • Thanks for the feedback. If my answer helped you in any way I would very appreciate if you accepted it and/or upvoted :) – Wojtek_B Mar 01 '21 at 11:51
  • 1
    Part of the issue was that Google CDN was ignoring several of the header rules and they needed to be written into the load balancer – GlennB Apr 16 '21 at 01:10