如何在Next.js应用中解决链接预加载警告?

huangapple go评论92阅读模式
英文:

How to fix link preload warning in Next.js app?

问题

我正在开发一个 Next.js 应用,版本是 13.4,控制台中出现了以下警告:

资源 <URL> 已使用链接预加载方式预加载,但在窗口加载事件后的几秒内未被使用。请确保它具有适当的 "as" 值,并且是有意预加载的。

错误的数量正在增加。

控制台截图:
如何在Next.js应用中解决链接预加载警告?

英文:

I am developing a Next.js app with version 13.4 and I am getting this warning in the console:

The resource <URL> was preloaded using link preload but not used within a few seconds from the window’s load event. Please make sure it has an appropriate as value and it is preloaded intentionally.

The number of the error is increasing.

The console screenshot:
如何在Next.js应用中解决链接预加载警告?

答案1

得分: 3

从警告图像来看,似乎您正在预加载CSS文件。在使用预加载时,您需要指定hrefas属性。我认为您尚未添加as属性。
请像这样添加它们。

<link rel="preload" href="style.css" as="style" />

查看此文档以获取更多详细信息。

英文:

From the warning image, it looks like you are preloading css files. While using preload, you will need to specify href and as attributes. I think you have not added as attribute.
Add them like this.

 <link rel="preload" href="style.css" as="style" />

Check this document for more details on this

答案2

得分: 0

我遇到了相同的问题,问题与谷歌字体有关,我成功解决了它,通过在尝试访问我想要的字体时添加preload:true。

示例:

export const font = Nunito({
  subsets: ["latin"],
  variable: "--font-general",
  preload: true,
});
英文:

I had the same issue and mine was about google fonts and i managed to solve it by adding preload:true when im trying to access to the font that i want.

Example:

export const font = Nunito({
  subsets: ["latin"],
  variable: "--font-general",
  preload: true,
});

huangapple
  • 本文由 发表于 2023年5月10日 21:26:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219016.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定