This post was published in 2020-11-02. Obviously, expired content is less useful to users if it has already pasted its expiration date.
(本文所涉及到的Cloudflare均为免费版:只有免费版才需要考虑这个问题)
在我的博客开始套Cloudflare以后,之前一直没有出现问题的webp converter for media出现了如下报错:
Your server uses the cache for redirects. The rules from .htaccess file or from Nginx configuration are not executed every time when the image is loaded, but the last redirect from cache is performed. With each request to image, your server should execute the rules from .htaccess file or from Nginx configuration. Now it only does this the first time and then uses cache. This means that if your server redirected image to WebP format the first time, it does so on every request. It should check the rules from .htaccess file or from Nginx configuration each time during request to image and redirect only when the conditions are met. Disable server cache for redirects. Please contact your server administrator.
看起来像是和cache有关的问题。排查完本地cache插件以后,我尝试在cloudflare里开启了“Development Mode”,然后插件的报错消失了:
为了进一步测试,我在Cloudflare控制台里创建了一条页面规则来屏蔽所有cache:truxton2blog.com/* Cache Level: Bypass ,最终确定了WebP Converter for Media的报错来源于Cloudflare cache。
确认了报错来源以后需要在以下两个解决方法里选择一个:
1,在page rules里添加规则truxton2blog.com/*.png(*.jpg) Cache Level: Bypass . 这条规则会屏蔽所有jpg/png格式图片的cache,强制让webp文件跳过Cloudflare cache,浪费了一大块Cloudflare白送的优良服务。
2,不再使用WebP Converter for Media插件,让Cloudflare cache接管一切,浪费了60%甚至更多的webp压缩率。由于没有使用其他webp相关的服务,部分多图页面加载流量大大增加。
这是一个节约服务器资源和改善页面加载效率的trade-off。我选择了方法1,牺牲图片的cache机会换取webp的优良压缩性能。