Using the Public Directory for Static Assets in Astro
📖 Scenario: You are building a simple Astro website that needs to display a logo image and a favicon. These files should be served as static assets from the public directory so they can be accessed directly by the browser.
🎯 Goal: Create an Astro project structure that uses the public directory to store static files. Then, reference these files correctly in your Astro component so the logo image and favicon appear on the page.
📋 What You'll Learn
Create a
public directory at the root of the Astro projectAdd a logo image file named
logo.png inside the public directoryAdd a favicon file named
favicon.ico inside the public directoryReference the logo image in the Astro component using the correct path
Add a
<link> tag in the component's <head> to use the favicon💡 Why This Matters
🌍 Real World
Websites often need to serve images, icons, and other files directly to users. The public directory is the standard way to organize and serve these static assets efficiently.
💼 Career
Understanding how to manage static assets is essential for front-end developers and web designers. It ensures websites load resources correctly and improves user experience.
Progress0 / 4 steps