V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
zhshch

让站点图片加载速度更快-Caddy webp 无感自动转换插件

  •  
  •   zhshch · Mar 30, 2020 · 2651 views
    This topic created in 2227 days ago, the information mentioned may be changed or developed.

    之前看到 https://www.v2ex.com/t/648915 发现 Amazing 啊,但是单独开一个服务感觉怪怪的。

    于是有 https://github.com/zhshch2002/caddy-webp

    screenshot.png

    参考了 https://github.com/webp-sh/webp_server_go 的代码,包括对 Safari 的处理。

    最重要的一点是——我们访问的 URL 可以完全不用改变,访客访问的依然是 https://image.nova.moe/tsuki/tsuki.jpg ,但是得到的图片格式为:image/webp,而且体积减少了不少。
    

    这一点也实现了,只需要在 Caddyfile 里加一个webp指令,就可以截取root下的文件来自动转换。(如果把顺序提升到 proxy 之前,是不是也可处理以反代后端相应的图片,待会试试)

    本质上插件是截取的正常 Handler 的响应,识别 content type,然后换成 webp,大功告成!

    by the way,这只是个实验性的插件,没有特别完善

    4 replies    2020-04-03 18:54:56 +08:00
    INTEL2333
        1
    INTEL2333  
       Mar 30, 2020
    好像不错,这个插件+cf 美滋滋
    DonnyChao
        2
    DonnyChao  
       Mar 30, 2020 via Android
    @INTEL2333 CF pro 版不是自带 webp 压缩优化功能
    heiybb
        3
    heiybb  
       Mar 30, 2020
    要是 Safari 也能支持 webp 就好了
    直接 CDN 上就直传 webp 图片
    INTEL2333
        4
    INTEL2333  
       Apr 3, 2020 via Android
    @DonnyChao 是的吖,但是不知道为什么 webp 生成的好慢,然后我这个是混用的(。•́︿•̀。)还有 quic 要靠这个苟苟
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2489 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 15:39 · PVG 23:39 · LAX 08:39 · JFK 11:39
    ♥ Do have faith in what you're doing.