0
0
NextJSframework~10 mins

Public directory for static files in NextJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access a static image from the public directory in Next.js.

NextJS
<img src="/[1]" alt="Logo" />
Drag options to blanks, or click blank then click option'
Apublic/logo.png
Blogo.png
C/logo.png
Dstatic/logo.png
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'public/' in the src path like 'public/logo.png'
Using relative paths like './logo.png' instead of root-based paths
2fill in blank
medium

Complete the code to link a CSS file located in the public directory inside the <head> of a Next.js page.

NextJS
<head>
  <link rel="stylesheet" href="/[1]" />
</head>
Drag options to blanks, or click blank then click option'
Astyles.css
Bcss/styles.css
Cpublic/styles.css
D/styles.css
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'public/' prefix in href
Using relative paths like './styles.css'
3fill in blank
hard

Fix the error in the code to correctly reference a JSON file in the public directory.

NextJS
fetch('/[1]')
  .then(res => res.json())
  .then(data => console.log(data))
Drag options to blanks, or click blank then click option'
Apublic/data.json
Bdata.json
C/data.json
Djson/data.json
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'public/' in the fetch URL
Using relative paths like './data.json'
4fill in blank
hard

Fill both blanks to create a link to a PDF file in the public directory and set it to open in a new tab.

NextJS
<a href="/[1]" target="[2]" rel="noopener noreferrer">Download PDF</a>
Drag options to blanks, or click blank then click option'
Afiles/manual.pdf
B_blank
C_self
Dmanual.pdf
Attempts:
3 left
💡 Hint
Common Mistakes
Using relative paths without leading slash
Forgetting to set target to '_blank' for new tab
5fill in blank
hard

Fill all three blanks to create an image tag that loads a picture from the public folder, sets alt text, and adds a CSS class.

NextJS
<img src="/[1]" alt="[2]" className="[3]" />
Drag options to blanks, or click blank then click option'
Aimages/photo.jpg
BA beautiful scenery
Cphoto-style
Dphoto.jpg
Attempts:
3 left
💡 Hint
Common Mistakes
Using relative paths without leading slash
Leaving alt attribute empty
Using 'class' instead of 'className' in JSX