performance - 如果是 Chrome,请使用 WebP

标签 performance google-chrome optimization opera webp

由于目前只有 Chrome 和 Opera 支持 WebP,我想知道是否可以针对这两个特定浏览器并将它们重定向以获取我网站的另一个版本,以便我可以帮助我更快地优化我的网站下载速度?

谢谢。

最佳答案

我这样解决了这个问题:

  • 检查客户端是否在 Accept header 中宣传“image/webp”
  • 如果支持 WebP,请检查本地 WebP 文件是否在磁盘上,以及 上 table
  • 如果服务器配置为代理,则附加一个“WebP: true” header 并 转发到后端
  • 如果提供 WebP Assets ,则附加“Vary: Accept”

在 Nginx 中:

location / {
    if ($http_accept ~* "webp") { set $webp "true"; }
    # Use $webp variable to add correct image. 
}

就我而言,我使用 thumbor 软件来转换图像。 https://github.com/globocom/thumbor

pip install thumbor

我的 session :

upstream thumbor  {
    server 127.0.0.1:9990;
    server 127.0.0.1:9991;
    server 127.0.0.1:9992;
    server 127.0.0.1:9993;
    server 127.0.0.1:9994;
}
location / {
    if ($http_accept ~* "webp") {
        set $webp "T";
    }
    if ($uri ~* "(jpg|jpeg)$") {
         set $webp "${webp}T";
    }
    proxy_cache_key $host$request_uri$webp;

    if ($webp = "TT") {
        rewrite ^(.*)$ "/unsafe/smart/filters:format(webp)/exemple.com$uri" break;
        proxy_pass http://thumbor;
        add_header Content-Disposition "inline; filename=image.webp";
    }
    if ($webp != "TT") {
        proxy_pass http://exemple.com;
    }
}

关于performance - 如果是 Chrome,请使用 WebP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15165311/

相关文章:

performance - 矩阵乘法中的超线程和涡轮增压 - 使用超线程的性能更差

python - 对 3D 空间中的所有点进行叉积

c# - HtmlGenericControl ("a") 与 HtmlAnchor

jquery mobile在chrome上显示居中的灰色圆圈

c# - 智能 ASCII 字符串表示

python - 从列表/队列中删除一些项目的快速方法

Django QuerySets 和缓存

java - 可变大小块的高效定位

javascript - Chrome 扩展 - cookies.getAll 不返回任何内容

java - 从渲染器接收消息超时 : 10. 000