Bird
Raised Fist0
Astroframework~8 mins

Project structure overview in Astro - Performance & Optimization

Choose your learning style10 modes available
Performance: Project structure overview
MEDIUM IMPACT
This affects the initial page load speed and developer efficiency by organizing files for optimal build and caching.
Organizing project files for faster build and load
Astro
src/components/Header.astro
src/components/Footer.astro
src/pages/index.astro
src/utils/helpers.js
public/assets/images/logo.png

// Clear separation of components, pages, utils, and public assets
Separating files by type allows build tools to optimize caching and incremental builds, improving load speed.
šŸ“ˆ Performance Gainreduces build time by 20-40%; improves cache hit rate, speeding LCP
Organizing project files for faster build and load
Astro
src/components/Header.astro
src/components/Footer.astro
src/pages/index.astro
src/utils/helpers.js
src/assets/images/logo.png

// All files mixed in one folder without separation
Mixing all files in one folder causes slower build times and harder caching, increasing page load time.
šŸ“‰ Performance Costbuild time increases linearly with file count; cache misses cause slower LCP
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Mixed file structureN/AN/AN/A[X] Bad
Organized file structureN/AN/AN/A[OK] Good
Rendering Pipeline
The project structure influences how build tools bundle and cache assets, affecting the critical rendering path by controlling what files are loaded and when.
→Build
→Cache
→Network Load
→Render
āš ļø BottleneckBuild and cache efficiency
Core Web Vital Affected
LCP
This affects the initial page load speed and developer efficiency by organizing files for optimal build and caching.
Optimization Tips
1Separate components, pages, and assets into distinct folders.
2Keep public assets outside the source folder for better caching.
3Organize utilities and helpers separately to enable incremental builds.
Performance Quiz - 3 Questions
Test your performance knowledge
How does a well-organized project structure affect page load performance?
AIt improves build caching and reduces load time
BIt increases the number of HTTP requests
CIt causes more layout shifts during rendering
DIt has no impact on performance
DevTools: Network
How to check: Open DevTools > Network tab, reload page, and observe asset loading order and cache status
What to look for: Look for cache hits (status 304) and minimal blocking requests indicating good structure

Practice

(1/5)
1. In an Astro project, which folder is primarily used to store your source code like components and pages?
easy
A. src/
B. public/
C. assets/
D. dist/

Solution

  1. Step 1: Understand folder roles in Astro

    The src/ folder is where you put your source code like components, pages, and styles.
  2. Step 2: Identify the correct folder for code

    The public/ folder is for static files like images, not code.
  3. Final Answer:

    src/ -> Option A
  4. Quick Check:

    Source code folder = src/ [OK]
Hint: Code lives in src/, static files in public/ [OK]
Common Mistakes:
  • Confusing public/ with src/
  • Thinking assets/ is default code folder
  • Assuming dist/ holds source code
2. Which of the following is the correct way to reference a static image stored in the public/ folder inside an Astro component?
easy
A. <img src="../src/images/photo.jpg" />
B. <img src="src/images/photo.jpg" />
C. <img src="/images/photo.jpg" />
D. <img src="./public/images/photo.jpg" />

Solution

  1. Step 1: Understand how public/ files are served

    Files in public/ are served from the root URL, so you reference them with a leading slash.
  2. Step 2: Choose the correct path format

    Using /images/photo.jpg correctly points to public/images/photo.jpg.
  3. Final Answer:

    <img src="/images/photo.jpg" /> -> Option C
  4. Quick Check:

    Static files use root-relative paths [OK]
Hint: Static files use root-relative paths starting with '/' [OK]
Common Mistakes:
  • Using relative paths like 'src/images' for public files
  • Including 'public/' in the path
  • Using relative paths that don't work in deployed site
3. Given this Astro project structure:
project/
ā”œā”€ public/
│  └─ logo.png
ā”œā”€ src/
│  └─ components/
│     └─ Header.astro
└─ src/pages/index.astro

What will be the correct way to display logo.png inside Header.astro?
medium
A. <img src="src/public/logo.png" alt="Logo" />
B. <img src="../public/logo.png" alt="Logo" />
C. <img src="./logo.png" alt="Logo" />
D. <img src="/logo.png" alt="Logo" />

Solution

  1. Step 1: Recall how public/ files are served

    Files in public/ are served from the root URL, so you use a root-relative path starting with '/'.
  2. Step 2: Apply correct path in component

    Using /logo.png correctly points to the image regardless of component location.
  3. Final Answer:

    <img src="/logo.png" alt="Logo" /> -> Option D
  4. Quick Check:

    Public files use root-relative paths [OK]
Hint: Always use root-relative paths for public folder files [OK]
Common Mistakes:
  • Trying to use relative paths to public/ folder
  • Including 'public' in the path
  • Using relative paths that break on deployment
4. You see this error when running your Astro project:
Cannot find module './public/image.png'
What is the likely cause based on Astro's project structure?
medium
A. The src/ folder is missing
B. Trying to import a static file from public/ using a relative import
C. The public/ folder is inside src/
D. The image file is corrupted

Solution

  1. Step 1: Understand how static files are accessed

    Static files in public/ are not imported via relative paths in code; they are referenced by URL paths.
  2. Step 2: Identify the error cause

    Trying to import a file from public/ using a relative import causes this error.
  3. Final Answer:

    Trying to import a static file from public/ using a relative import -> Option B
  4. Quick Check:

    Static files are referenced by URL, not imported [OK]
Hint: Never import files from public/; use URL paths [OK]
Common Mistakes:
  • Importing images or static files as modules
  • Placing public/ inside src/
  • Assuming public/ files are bundled like code
5. You want to add a new page to your Astro site at URL /about. Where should you place the new file in the project structure?
hard
A. src/pages/about.astro
B. public/about/index.html
C. src/components/about.astro
D. src/about.astro

Solution

  1. Step 1: Understand Astro's page routing

    Files inside src/pages/ map directly to site URLs.
  2. Step 2: Choose correct location for new page

    Placing about.astro inside src/pages/ creates the /about route.
  3. Final Answer:

    src/pages/about.astro -> Option A
  4. Quick Check:

    Pages go in src/pages/ folder [OK]
Hint: Put new pages in src/pages/ for routing [OK]
Common Mistakes:
  • Placing pages in src/components/
  • Adding pages directly in src/ without pages folder
  • Putting pages in public/ folder
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard