perf(图片加载): 优化图片加载逻辑,简化解码处理
移除冗余的解码检查逻辑,直接使用现代浏览器的异步解码特性 添加fetchPriority优化加载优先级,提升页面性能
This commit is contained in:
parent
6618f67be2
commit
4e59e868aa
|
|
@ -21,14 +21,9 @@
|
|||
const img = new Image();
|
||||
const record = { img: img, ready: false };
|
||||
window.YooneSnowImageCache[imageUrl] = record;
|
||||
img.onload = function(){
|
||||
var decoder = img.decode && typeof img.decode === 'function' ? img.decode() : null;
|
||||
if (decoder && typeof decoder.then === 'function'){
|
||||
decoder.then(function(){ record.ready = true; }).catch(function(){ record.ready = true; });
|
||||
} else {
|
||||
record.ready = true;
|
||||
}
|
||||
};
|
||||
try { img.decoding = 'async'; } catch(e) {}
|
||||
try { img.fetchPriority = 'low'; } catch(e) {}
|
||||
img.onload = function(){ record.ready = true; };
|
||||
img.onerror = function(){
|
||||
// 加载失败 从缓存移除避免重复错误
|
||||
delete window.YooneSnowImageCache[imageUrl];
|
||||
|
|
|
|||
Loading…
Reference in New Issue