Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 如果是Chrome,请使用WebP_Performance_Google Chrome_Optimization_Opera_Webp - Fatal编程技术网

Performance 如果是Chrome,请使用WebP

Performance 如果是Chrome,请使用WebP,performance,google-chrome,optimization,opera,webp,Performance,Google Chrome,Optimization,Opera,Webp,因为目前只有Chrome和Opera支持WebP,我想知道我是否可以针对这两个特定的浏览器,将它们重定向到我的网站的另一个版本,这样我就可以更快地优化我的网站下载速度 谢谢 我这样解决了这个问题: 检查客户端是否在Accept标头中播发“image/webp” 如果支持WebP,请检查本地WebP文件是否在磁盘上,以及 上菜 若服务器配置为代理,则附加一个“WebP:true”头和 转发到后端 如果提供了WebP资产,则附加“Vary:Accept” 在Nginx中: location /

因为目前只有Chrome和Opera支持WebP,我想知道我是否可以针对这两个特定的浏览器,将它们重定向到我的网站的另一个版本,这样我就可以更快地优化我的网站下载速度


谢谢

我这样解决了这个问题:

  • 检查客户端是否在Accept标头中播发“image/webp”
  • 如果支持WebP,请检查本地WebP文件是否在磁盘上,以及 上菜
  • 若服务器配置为代理,则附加一个“WebP:true”头和 转发到后端
  • 如果提供了WebP资产,则附加“Vary:Accept”
在Nginx中:

location / {
    if ($http_accept ~* "webp") { set $webp "true"; }
    # Use $webp variable to add correct image. 
}
在我的例子中,我使用拇指或软件来转换图像。

我的确认:

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;
    }
}

目前,thumbor支持自动webp转换:

您仍然需要配置负载平衡器以传递webp accepts头,但除此之外,thumbor将为您处理所有事情


希望有帮助

很好的问题,只是不是合适的论坛(请参阅常见问题解答)检查$\u服务器上的用户代理,然后重定向到相应的页面。有关于正确设置webP的好文档。
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;
    }
}