0
0
NextJSframework~20 mins

Public directory for static files in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Public Directory Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Accessing static files from the public directory
In a Next.js app, you place an image named logo.png inside the public folder. What URL path should you use in an <img> tag to display this image correctly?
NextJS
<img src="/logo.png" alt="Logo" />
A<img src="/logo.png" alt="Logo" />
B<img src="/public/logo.png" alt="Logo" />
C<img src="/static/logo.png" alt="Logo" />
D<img src="logo.png" alt="Logo" />
Attempts:
2 left
💡 Hint
Files in the public folder are served from the root URL path.
📝 Syntax
intermediate
2:00remaining
Correct usage of public directory for CSS file
You want to include a CSS file named styles.css located in the public folder in your Next.js app. Which is the correct way to link it in the <head> of your page?
NextJS
<link rel="stylesheet" href="/styles.css" />
A<link rel="stylesheet" href="/styles.css" />
B<link rel="stylesheet" href="styles.css" />
C<link rel="stylesheet" href="/public/styles.css" />
D<link rel="stylesheet" href="/static/styles.css" />
Attempts:
2 left
💡 Hint
Remember how public folder files are served in Next.js.
🔧 Debug
advanced
2:00remaining
Why does this image not load from public directory?
You placed banner.jpg inside the public/images folder. Your component uses <img src="/images/banner.jpg" alt="Banner" /> but the image does not show. What is the most likely cause?
NextJS
<img src="/images/banner.jpg" alt="Banner" />
AThe image path is correct; the problem is the image file is corrupted.
BYou must import the image in the component to use it.
CThe public folder is not for images; images must be in the static folder.
DThe image path is correct; the problem is the image file is missing or misnamed.
Attempts:
2 left
💡 Hint
Check the file name and location carefully.
🧠 Conceptual
advanced
2:00remaining
Behavior of files in public directory during build
What happens to files inside the public directory when you build and deploy a Next.js app?
AThey are ignored and not included in the build output.
BThey are bundled and minified into JavaScript files.
CThey are copied as-is to the root of the deployed site and served statically.
DThey are moved to the <code>_next/static</code> folder and renamed.
Attempts:
2 left
💡 Hint
Think about how static assets should be served.
state_output
expert
2:00remaining
Effect of modifying files in public directory on hot reload
You are running a Next.js development server. You add a new file icon.svg to the public folder. What happens immediately in the browser?
AThe browser automatically reloads and shows the new file if referenced.
BThe browser does not reload; you must refresh manually to see the new file.
CNext.js throws an error because public folder changes are not allowed during dev.
DThe development server crashes and restarts.
Attempts:
2 left
💡 Hint
Consider how Next.js watches files in the public folder during development.