How do you handle static assets in Next.js?

Instruction: Describe the approach to managing static assets like images in a Next.js application.

Context: Handling static assets efficiently is key to performance in web applications. This question aims to gauge the candidate's knowledge of best practices in Next.js.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Put fixed public files in public and reference them from the site root: public/logo.png is addressed as /logo.png, not /public/logo.png. Keep credentials and private documents out of that directory. It is also not a durable upload store for a deployment whose filesystem is replaced or shared across instances.

Treat public files and fingerprinted build assets differently. Next.js normally serves public files with Cache-Control: public, max-age=0 because their names may be reused...

Related Questions