原想使用该功能是加速网站的图片,但结果是不理想。
安装
account_id = "bb9693ef4db8082e0c871ff851012363" webpack_config = "webpack.config.js" type = "javascript" workers_dev = true [env.production] name = "image" route = "laomiao.site/*" zone_id = "bc5a62035d150b36f3641acecc4f793c" account_id = "bb9693ef4db8082e0c871ff851012363"
修改 wrangler.toml 文件内容。
运行:
npm install npm run build npm install -g @cloudflare/wrangler wrangler publish --env production -c wrangler.toml
URL 例子:
image.laomiao.workers.dev/https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fs3-us-west-2.amazonaws.com%252Fsecure.notion-static.com%252F3cdc5ae3-12a2-4c0c-83fa-0dce8b4e5b3c%252Fphoto-1493612276216-ee3925520721.webp%3Ftable%3Dblock%26id%3D264a87f9-0dc0-4edc-b800-e9260d1d0a61%26cache%3Dv2
- 后面的是你原始图片地址
应用
CF 部署后,然后给我的 LaoMiao.site 网站应用,我的网站采用该项目搭建 。
打开根目录下 site.config.js 文件,修改如下图的配置:
![图片 CDN](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fd54b0f25-9426-4b83-9c51-2e6165a030b2%2F694ff22e-956a-4570-8bce-e1de4cdbeaff%2FUntitled.png%3Ftable%3Dblock%26id%3D93a2542d-ddad-43d7-b0a1-3370e6a21e52%26spaceId%3Dd54b0f25-9426-4b83-9c51-2e6165a030b2%26expirationTimestamp%3D1725746400000%26signature%3DL2a1cayEVyrPvUxcCGNa4pKIQk_YRov3FbvBn_aDETs?table=block&id=93a2542d-ddad-43d7-b0a1-3370e6a21e52&cache=v2)
我的配置是:
imageCDNHost: "https://image.laomiao.workers.dev"
该域名请使用自己的配置,不要使用我这个,因为不知掉哪一天就无法使用了
速度对比
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fd54b0f25-9426-4b83-9c51-2e6165a030b2%2Faa7827bf-21b6-47a0-a14d-405232917b27%2FUntitled.png%3Ftable%3Dblock%26id%3Dfe7d95d6-6664-4ed4-9fe9-0b0164540c4e%26spaceId%3Dd54b0f25-9426-4b83-9c51-2e6165a030b2%26expirationTimestamp%3D1725746400000%26signature%3DJ367z70TMZYiYe6n139LUPTv1OAyF4OV0KCxryfQxJA?table=block&id=fe7d95d6-6664-4ed4-9fe9-0b0164540c4e&cache=v2)
从结果看出,使用 CF 后的变化:
- 平均速度提升了一点
- 最慢速度很夸张
- 最快速度提升
总结:不够稳定,不建议去使用。