在当今破碎的网络图标环境中(令人惊讶的是).svg
图标尚未获得广泛支持,人们可能会想在头部添加大量元素指向任意数量的
favicons
icons
apple-touch-icons
safari-pinned-tabs
mstiles
等等
任何页面上的图标、图标、触摸图标、磁贴等的综合列表将是巨大的。
这会影响页面初始化和加载时间,在某些情况下会非常显着。
goldilocks 解决方案是能够根据<link>
需要添加尽可能多的图标引用,而不会影响页面加载性能。
那么......异步加载这些元素是一种合法的方法吗?
例如。
const favIcon = {'rel' : 'icon', 'href' : 'favicon.ico'};
const appleTouchIcon = {'rel' : 'apple-touch-icon', 'href' : 'apple-touch-icon.png'};
const myIcons = [favIcon, appleTouchIcon];
for (let i = 0; i < myIcons.length; i++) {
let myIcon = document.createElement('link');
myIcon.rel = myIcons[i].rel;
myIcon.href = myIcons[i].href;
document.head.appendChild(myIcon);
}
<link>
或者异步加载这些元素是否DOMContentLoaded
意味着各种用户代理会错过他们正在寻找的图标?