Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 838 Bytes

static-file-serving.md

File metadata and controls

21 lines (14 loc) · 838 Bytes
description
Next.js allows you to serve static files, like images, in the public directory. You can learn how it works here.

Static File Serving

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 (/).

For example, if you add an image to public/my-image.png, the following code will access the image:

function MyImage() {
  return <img src="/my-image.png" alt="my image" />
}

export default MyImage

Don't name the public directory anything else. The name can't be changed and is the only directory that Next.js uses to serve static assets.

Make sure you don’t have static assets in conflict with files in the pages directory, as this will result in an error.