Skip to content

public

Next.js 可以在根目录中名为 public 的文件夹下提供静态文件,例如图片。然后,你的代码可以从基本 URL (/) 开始引用 public 内的文件。

¥Next.js can serve static files, like images, under a folder called public in the root directory. Files inside public can then be referenced by your code starting from the base URL (/).

例如,访问 /avatars/me.png 路径可以查看文件 public/avatars/me.png。显示该图片的代码可能如下所示:

¥For example, the file public/avatars/me.png can be viewed by visiting the /avatars/me.png path. The code to display that image might look like:

缓存

¥Caching

Next.js 无法安全地将资源缓存在 public 文件夹中,因为它们可能会发生变化。应用的默认缓存标头是:

¥Next.js cannot safely cache assets in the public folder because they may change. The default caching headers applied are:

机器人、网站图标等

¥Robots, Favicons, and others

对于静态元数据文件,例如 robots.txtfavicon.ico 等,你应该在 app 文件夹中使用 特殊元数据文件

¥For static metadata files, such as robots.txt, favicon.ico, etc, you should use special metadata files inside the app folder.