如何知道 window 的 load 事件已经触发

背景

为了使页面加载更快,常常将一些不重要的第三方脚本在页面完成加载后进行懒加载。

// 做一些不影响业务的事情
window.addEventListener('load', () => {
  // 懒加载埋点分析
  loadScript({
    url: 'https://www.domain.com/test.js',
    timeout: 10000
  }).then(() => {
    console.log('ok');
  }).catch(console.error);
  // 其他
  // ...
});

"如何知道 window 的 load 事件已经触发"继续阅读

Resource Hints – What is Preload, Prefetch, and Preconnect?[转]

Today we are going to explore current resource hints and directives which can be another great way to boost the performance on your website or web application. You might have heard of preload, prefetch, and preconnect, but we want to dive deeper into the differences between them how you can benefit from them. Some of the advantages of these is that they allow web developers to optimize delivery of resources, reduce round trips, and fetch resources to deliver content faster while a user is browsing a page.

"Resource Hints – What is Preload, Prefetch, and Preconnect?[转]"继续阅读