modernizr - WebP 不能在移动设备上运行,但可以在桌面上运行?
问题描述
我使用将我所有的图像转换为 WebP,gulp-webp
并使用 Modernizr 检查是否启用了 webp,如果启用,则使用 webp url 创建一个新的 img 标签。据我在谷歌页面速度上看到的,它在桌面上按预期工作,但在移动设备上,它Serve images in next-gen formats
仍然说。
您是否需要采取其他步骤才能使其在移动设备上运行?我在任何地方都找不到任何关于它的信息,我已经完全按照 Modernizr 所说的那样设置了 webp。
任何帮助,将不胜感激。
Modernizr.on('webp', function (result) {
$('.noscript').each(function() {
let img = document.createElement('img');
img.alt = this.getAttribute('data-alt');
img.className = this.getAttribute('data-class');
if (result) {
img.src = this.getAttribute('data-webp');
} else {
img.src = this.getAttribute('data-original');
}
this.parentNode.insertBefore(img, this.nextSibling);
});
});
然后我会在 HTML 中执行此操作:
<noscript data-alt="Payment Logos" data-original="/images/common/payment-foot.png" data-webp="/dist/images/common/payment-foot.webp" data-class="mobileHide lazyload" class="noscript">
<img src="/images/common/payment-foot.png" alt="" class="mobileHide">
</noscript>
解决方案
推荐阅读
- python - 如何在 Windows 中的 Python 3.9 下 pip install pickle?
- sql - group by 函数在 PostgreSQL 中是如何工作的?(初学者)
- python - 如何使来自 yaml conda 环境的通道顺序保持不变?
- javascript - 如何为 Ionic/React 项目中的 Mapbox GL JS 地图动态设置地图容器高度
- javascript - 3个不同班级之间的过渡
- reactjs - Material-UI Box 组件对齐方式
- excel - 来自不同工作表的 VBA Vlookup
- mpi - 让 mpirun 命令继承当前环境的最佳方法?
- bash - 如何将参数传递给 bashrc 函数?
- sympy - Sympy 的 LUsolve 在哪里定义?