消除放大器页面上的渲染资源字体

发布于 2025-01-21 15:23:37 字数 563 浏览 3 评论 0原文

Google Lighthouse提出了AMP页面的问题

我尝试了多种解决方案,但不起作用

<link rel="preload" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap" as="font" crossorigin>
<link rel="preload" href="https://fonts.googleapis.com/css?family=Cairo:300,400,600,700&subset=arabic,latin-ext&display=swap" as="font" crossorigin>

Google Lighthouse raising issues of AMP Pages
enter image description here

I tried multiple solutions but not working

<link rel="preload" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap" as="font" crossorigin>
<link rel="preload" href="https://fonts.googleapis.com/css?family=Cairo:300,400,600,700&subset=arabic,latin-ext&display=swap" as="font" crossorigin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

说好的呢 2025-01-28 15:23:37

这对我有帮助(提出HTML索引):

<style>
 @import url('https://fonts.googleapis.com/css2? 
 family=Open+Sans:wght@500;600;700;800&display=swap');
</style>

This helped me (put in HTML index):

<style>
 @import url('https://fonts.googleapis.com/css2? 
 family=Open+Sans:wght@500;600;700;800&display=swap');
</style>
很酷不放纵 2025-01-28 15:23:37

您可以添加一个Onload侦听器以将rel属性从PRELOAD更改为stylesheet

这看起来很像:

<link
  rel="preload"
  href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap"
  onload="this.onload=null;this.rel='stylesheet'"
  as="style"
>

您可以在 web.dev

You can add a onload listener to change the rel attribute from preload to stylesheet

this will look something like:

<link
  rel="preload"
  href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap"
  onload="this.onload=null;this.rel='stylesheet'"
  as="style"
>

You can read more about this topic at web.dev

桃扇骨 2025-01-28 15:23:37

web.dev 表示您应该以这种方式预订:

<link rel="preload" 
      href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap"
      as="style"
      onload="this.onload=null; this.rel='stylesheet'; document.body.classList.add('fonts-loaded')">

但是请使用另一种字体,但是要使用另一种字体直至字体已加载:

body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body.fonts-loaded {
  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

web.dev says that you should preload in this way:

<link rel="preload" 
      href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap"
      as="style"
      onload="this.onload=null; this.rel='stylesheet'; document.body.classList.add('fonts-loaded')">

But use another font till fonts are loaded:

body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body.fonts-loaded {
  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文