0
0
Astroframework~20 mins

Public directory for static assets in Astro - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Astro Static Assets Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Astro serve files from the public directory?
In Astro, you place static files like images or fonts in the public directory. What happens when you reference /logo.png in your component?
AAstro bundles the file inside JavaScript and serves it only when imported in components.
BAstro copies the file to the build output and serves it at the root URL, so <code>/logo.png</code> works directly.
CAstro ignores files in <code>public</code> and you must import them manually to use.
DAstro requires you to configure a special plugin to serve files from <code>public</code>.
Attempts:
2 left
💡 Hint
Think about how static assets are usually served in web projects.
📝 Syntax
intermediate
2:00remaining
Correct way to reference a static asset in Astro component
You have an image banner.jpg inside the public folder. Which is the correct way to display it in an Astro component?
A<img src="/banner.jpg" alt="Banner" />
B<img src="./public/banner.jpg" alt="Banner" />
C<img src="../public/banner.jpg" alt="Banner" />
D<img src="banner.jpg" alt="Banner" />
Attempts:
2 left
💡 Hint
Remember how URLs relate to the public folder in Astro.
🔧 Debug
advanced
2:00remaining
Why does this static asset not load in Astro?
You placed icon.svg inside src/assets and referenced it as /icon.svg in your component. Why does it fail to load?
AAstro requires a special config to serve SVG files from <code>src/assets</code>.
BYou must import <code>icon.svg</code> as a module to use it in Astro components.
CThe file path is correct; the problem is a missing alt attribute.
DFiles in <code>src/assets</code> are not served as static assets; only <code>public</code> folder files are served at root.
Attempts:
2 left
💡 Hint
Think about which folders Astro treats as static asset sources.
🧠 Conceptual
advanced
2:00remaining
What happens to files in the public directory during Astro build?
During the build process, how does Astro handle files inside the public directory?
AAstro copies all files from <code>public</code> directly to the build output folder without modification.
BAstro optimizes and bundles all files from <code>public</code> into JavaScript chunks.
CAstro ignores the <code>public</code> folder during build and serves files only in development.
DAstro converts all images in <code>public</code> to base64 strings embedded in HTML.
Attempts:
2 left
💡 Hint
Think about static files and how they should be served in production.
state_output
expert
3:00remaining
How does referencing a public asset affect component reactivity in Astro?
You have an Astro component that displays an image from the public folder. If you change the image file in public and rebuild, what happens to the component's rendered output?
AThe component caches the old image and never updates unless you change the component code.
BAstro automatically reloads the component state to reflect the new image without rebuilding.
CThe component shows the updated image immediately after rebuild because the public asset URL stays the same but the file content changes.
DThe component breaks because Astro cannot detect changes in public assets.
Attempts:
2 left
💡 Hint
Think about how static files and rebuilds affect what the browser loads.