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