Google Lighthouse错误加载webp图像

时间:2019-07-05 12:56:20

标签: nginx webp lighthouse

我正在尝试提高我在Google灯塔上的效果得分。有人建议使用下一代图像格式,包括webp,因此我使用Nginx config来实现服务webp代替图像,其中请求接受标头包括webp的图像...

map $http_accept $webp_suffix {
  default   "";
  "~*webp"  ".webp";
}

server {
  root /www/;
  listen 80 default_server;
  index index.html;

  location ~* ^\/images\/ {
    expires max;
    add_header Vary Accept;
    try_files $uri$webp_suffix $uri =404;
  }

  location / {
    try_files $uri $uri/index.html =404;
  }

  error_page 404 /404.html;
}

现在,页面加载速度大大提高,并且webp方法运行良好,可以回退到不存在webp或浏览器不支持的原始图像。但是,灯塔报告显示错误,因此我不确定我是否正确实施了所有内容。这个错误是什么意思?

lighthouse opportunities

2 个答案:

答案 0 :(得分:0)

将您的灯塔更新到2.4版以上

在以前的版本中,未正确处理webp扩展

https://github.com/GoogleChrome/lighthouse/issues/3364

如果这不起作用,则可能需要在Github上提交问题

答案 1 :(得分:0)

NGINX可能没有为它们提供正确的100MB MIME类型。

尝试将其添加到文件image/webp中并重新启动服务器:

/etc/nginx/mime.types