Modernizr 随机不在 Safari 中测试图像格式

Modernizr randomly not testing image formats in Safari

由于未知原因,我的 modernizr 在 Safari 中似乎随机地无法正常工作。

My modernizr build

简而言之,我主要检查图像格式(Webp、Jpeg2000 和 JpegXR),在 Chrome、Edge 和 Mozilla 中它工作得很好,我的问题是 Safari,在 IPad 上测试.

=> 我打算根据兼容性提供图像

html.webp.no-jpeg2000 {/** webp */}
html.jpeg-2000 {/** j2k */}
html.no-webp.no-jpeg2000 {/** fallback */}

我已经为自己构建了一个小脚本来“var_dump”我的 HTML classes:

$(document).ready(function() {
  var response = $("html").attr("class");
  $("<p>" + response + "</p>").appendTo("#header-nav");
})

在 Chrome 我的 class 符合预期:

svg xhrresponsetype atobbtoa atob-btoa canvas preserve3d placeholder xhrresponsetypejson xhrresponsetypetext svgclippaths svgasimg cssanimations webgl webpalpha webpanimation webplossless webp no-jpeg2000 no-jpegxr webp-alpha webp-animation webp-lossless

在 Safari 中,class如下:

svg xhrresponsetype atobbtoa atob-btoa canvas preserve3d placeholder xhrresponsetypejson xhrresponsetypetext svgclippaths svgasimg cssanimations webgl 

乍一看,它们是相同的,直到 class WebGL 出现之前都是如此。在这个class(测试)之后,它就停止了。有时我确实得到 all 图像相关的 classes,但大多数时候我得到 none,然后有时只有一两个在工作。

我试过了

添加第二个 modernizr 映像仅构建并将其放在 header 的最顶部。似乎给出了更一致的积极结果。

这个问题的原因是什么,还是我做错了什么?

我已经解决了,至少有点。

问题是我推迟了我的 modernizr。 是的,没有评论请....

尽管如此,我的脚本确实输出相同的 类,为什么会这样 - 我不知道,但肯定添加了 类。