I am having a performance with caching.
I am using WordPress with the ShortPixel adaptive images plugin to optimize my images on my website (www.nicholaswaton.com). I have set up a subdomain to serve the images from the Shortpixel optimizer.
I have been in touch with ShortPixel and they’ve set up their headers to make sure images are cached in CDNs for 30 days.
So it seems the images expire every day instead of being cached by CF
Just in case, I have set up also a page rule in CF to cache everything and to set the Edge TTL to one month. But it seems all these rules are not taken into account. These images never change.
I have been in touch with Shortpixel and they suggested for me to get in touch with CF.
What am I doing wrong? How can I make sure to get Cache HIT most of the time?
Edge Cache TTL is not a guarantee it will stay there for a month. Edge Cache TTL is more like a maximum amount of time it’s safe to cache a resource. Low-usage files get evicted from the cache early to make room for high-use resources.
Everything on www.nicholaswaton.com is getting a cache HIT, only things on img.nicholaswaton.com is getting a cache MISS even though the headers are saying to cache it longer.
Im getting a Cache HIT right now, but that doesnt mean that it is like this forever. Like already mentioned by @sdayman the max Cache Age and Cloudflare Edge Cache TTL only shows Cloudflare how long it is allowed to cache the File, but Cloudflare itself decides how long they will cache it in Reality. When a File is only Requested once every 24 Hours and the Colo that answered the Request has a lot of Traffic the File will get purged from Cloudflare Cache to make Space for Files that are requested more often
I am having a performance with caching.
I am using WordPress with the ShortPixel adaptive images plugin to optimize my images on my website (www.nicholaswaton.com). I have set up a subdomain to serve the images from the Shortpixel optimizer.
I have been in touch with ShortPixel and they’ve set up their headers to make sure images are cached in CDNs for 30 days.
So it seems the images expire every day instead of being cached by CF
Just in case, I have set up also a page rule in CF to cache everything and to set the Edge TTL to one month. But it seems all these rules are not taken into account. These images never change.
I have been in touch with Shortpixel and they suggested for me to get in touch with CF.
What am I doing wrong? How can I make sure to get Cache HIT most of the time?
I ended up deactivating Cloudflare to serve these images as the ShortPixel CDN is serving them much faster. You can see the improvement of performance on this graph. I removed the Cloudflare configured subdomain around April 15th.
Only a guess, but Its my impression that Cloudflare is not playing well with the fact that your images have a Content-type: image/webp header while their extension is the original image format (.jpg, for instance).:
That only applies for the question if cloudflare should Cache a File. He has a Pagerule in place to Cache Anything so the Extension is no Problem.
It could be a .bin and Cloudflare would still Cache it with this Rule in Place. And after a Visit i got Hit for images before he deactivated the Proxy for this Subdomain. Cloudflare simply seems to delete the Files out of the Cache pretty quickly. Probably to less Traffic so the Colo deleted the Cache after a few Hours
I ran a cURL from the SJC colo to this URL (found in the GTMetrix results you shared), not only did I get a MISS, but I also see that the image was modified recently < last-modified: Fri, 23 Apr 2021 16:54:16 GMT
If a resource is modified, then you would in theory see a MISS as the Cloudflare cache server would need to then reach back out to your origin server for a fresh copy of the file to cache when requested.
Is this expected behavior? Do you have something in place that would be modifying the resources, or are you manually changing them?
Images are processed on the fly and served from our CDN, in the next-gen WebP format, if the browser supports it.
@nicholas.waton ShortPixel Adaptive Images plugin isn’t really needed if you’re using Cloudflare in front especially with Pro and higher plans and Polish webP.
I think the OPs question is why the assets respond HIT today, but MISS tomorrow, when they have an Edge TTL of a month.
The answer is most likely “because they are not popular enough”. Cloudflare will not cache an infinite amount of content, and the least popular content will be evicted first. So if you have a low traffic site, your content will not be cached for as long as a month.
There is an Images Beta starting, which may avoid this.
@eva2000 well so far ShortPixel AI is giving much better performance and at a much cheaper cost than Cloudflare. I don’t really have the traffic to justify paying for Cloudflare Pro ($20/month). With ShortPixel AI you only pay for the number of images you optimize. 30.000 for $20. So I’ve been using ShortPixel AI for a few month, and have had just a one-time fee. Since January I’ve only used 13,000 credits.
Maybe Cloudflare is just not justified for my particular case. It is still surprising that Cloudflare would delete just the image assets every 24 hours. The rest is kept. At least it should be made a little bit more clear when you set up the configuration.
I use ShortPixel but not the AI plugin as I have a ShortPixel lifetime account but AI plugin requires jQuery but my Wordpress site doesn’t use jQuery (better page speed)
However, the $20 CF Pro plan does more than CDN serving. You get access to CF WAF and more Firewall rule/page rule quotas for security. And for page speed performance you gain Cloudflare TCP Turbo and Enhanced HTTP/2 Prioritization which may do more for page speed performance than what Shortpixel AI can do alone - given the particular current Google Core Web Vital metrics being focussed on.
Regarding CF Enhanced HTTP/2 Prioritization
This prioritization scheme allows sending the render-blocking content serially, followed by the visible images in parallel and then the rest of the page content with some level of sharing to balance application and content loading. The “* If Detectable” caveat is that not all browsers differentiate between the different types of stylesheets and scripts but it will still be significantly faster in all cases. 50% faster by default, particularly for Edge and Safari visitors is not unusual:
If you were on CF Pro and higher, you could utilise CF Cache Analytics to track over time a specific URL’s cache status so you could in theory see what goes from cache hit to miss and how many requests are made. Another advantage of paid Pro and higher plans
serving webP extension images via ShortPixel plugin conversion and picture srcset HTML code to workaround CF’s lack of HTTP Vary header support (there’s no need for ShortPixel AI in this case)
I think the answers throughout the thread and the great reply by @eva2000 address this specifically when Cloudflare is being used with ShortPixel, so I’m going to close this off for now.