Bird
Raised Fist0
Astroframework~5 mins

Prefetching and preloading in Astro - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is prefetching in Astro?
Prefetching in Astro means loading resources or pages in the background before the user clicks on them. This helps the site feel faster because the content is ready when needed.
Click to reveal answer
intermediate
How does preloading differ from prefetching?
Preloading tells the browser to load important resources immediately, so they are ready to use right away. Prefetching loads resources with low priority for future use.
Click to reveal answer
beginner
Which HTML tag attribute is commonly used for preloading resources?
The <link rel="preload" href="..." as="..."> tag is used to preload resources like scripts, styles, or fonts.
Click to reveal answer
beginner
Why is prefetching useful in Astro projects?
Prefetching helps Astro sites load pages faster by downloading linked pages or data in the background before the user visits them, improving user experience.
Click to reveal answer
intermediate
Name one way to enable prefetching in Astro.
You can add the prefetch attribute to <a> tags to tell Astro to prefetch the page when the user hovers or is likely to visit.
Click to reveal answer
What does prefetching do in Astro?
ARemoves unused resources from the page
BLoads resources in the background before user action
CDelays loading resources until user clicks
DBlocks page rendering until resources load
Which rel attribute is used to preload resources?
Apreload
Bprefetch
Cstylesheet
Dmodule
How do you enable prefetching on an Astro link?
AAdd <code>client:visible</code>
BAdd <code>client:idle</code>
CAdd <code>client:load</code>
DAdd <code>prefetch</code>
What is the main benefit of preloading?
ATo load important resources early for faster use
BTo load resources only when needed
CTo delay resource loading to save bandwidth
DTo cache resources permanently
Which is true about prefetching?
AIt blocks page rendering
BIt loads resources with high priority
CIt loads resources with low priority for future use
DIt removes unused CSS
Explain in your own words how prefetching improves user experience in Astro projects.
Think about what happens before the user clicks a link.
You got /4 concepts.
    Describe the difference between preloading and prefetching and when you might use each.
    Consider resource priority and timing.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of prefetching in Astro?
      easy
      A. To remove unused resources from the page
      B. To load resources immediately for current use
      C. To load resources in the background before they are needed
      D. To delay loading resources until user interaction

      Solution

      1. Step 1: Understand prefetching concept

        Prefetching means loading resources quietly in the background before the user needs them.
      2. Step 2: Compare with other options

        Preloading loads immediately, delaying is opposite, and removing resources is unrelated.
      3. Final Answer:

        To load resources in the background before they are needed -> Option C
      4. Quick Check:

        Prefetching = background loading [OK]
      Hint: Prefetching = load early but quietly in background [OK]
      Common Mistakes:
      • Confusing prefetching with preloading
      • Thinking prefetching delays loading
      • Assuming prefetching removes resources
      2. Which is the correct way to add a prefetch link in Astro's <head>?
      easy
      A.
      B.
      C.
      D.

      Solution

      1. Step 1: Identify correct rel attribute for prefetch

        Prefetch uses rel="prefetch" to hint browser to load resource in background.
      2. Step 2: Check other options

        Preload uses rel="preload", but question asks for prefetch. rel="fetch" is invalid.
      3. Final Answer:

        <link rel="prefetch" href="/script.js"> -> Option D
      4. Quick Check:

        Prefetch link uses rel="prefetch" [OK]
      Hint: Prefetch link uses rel="prefetch" exactly [OK]
      Common Mistakes:
      • Using preload instead of prefetch
      • Missing the rel attribute
      • Using invalid rel values like fetch
      3. Given this Astro component snippet, what will happen?
      <head>
        <link rel="preload" as="style" href="/styles.css" />
      </head>
      <body>
        <h1>Hello</h1>
      </body>
      medium
      A. The styles.css file loads immediately to style the page quickly
      B. The styles.css file loads in the background after page load
      C. The styles.css file is ignored by the browser
      D. The styles.css file loads only when user scrolls

      Solution

      1. Step 1: Understand preload with as="style"

        Preload with as="style" tells browser to load CSS immediately for fast styling.
      2. Step 2: Compare with prefetch behavior

        Prefetch loads in background, but preload loads right away to speed up rendering.
      3. Final Answer:

        The styles.css file loads immediately to style the page quickly -> Option A
      4. Quick Check:

        Preload with as="style" = immediate CSS load [OK]
      Hint: Preload with as="style" loads CSS immediately [OK]
      Common Mistakes:
      • Confusing preload with prefetch
      • Thinking preload delays loading
      • Ignoring the as attribute importance
      4. Identify the error in this Astro prefetch usage:
      <head>
        <link rel="prefetch" as="script" href="/app.js" />
      </head>
      medium
      A. Prefetch should not use the 'as' attribute
      B. The href attribute is missing
      C. rel="prefetch" is invalid in Astro
      D. The link tag must be inside the body

      Solution

      1. Step 1: Check prefetch attribute usage

        Prefetch links should not include the as attribute; it's only for preload.
      2. Step 2: Validate other attributes and placement

        The href is present, rel="prefetch" is valid, and link tags belong in head, not body.
      3. Final Answer:

        Prefetch should not use the 'as' attribute -> Option A
      4. Quick Check:

        Prefetch without 'as' attribute [OK]
      Hint: Prefetch links never use 'as' attribute [OK]
      Common Mistakes:
      • Adding 'as' attribute to prefetch
      • Placing link tags inside body
      • Confusing prefetch with preload
      5. You want to optimize loading a large image that will be shown on the next page in Astro. Which combination is best?
      hard
      A. Use <link rel="preload" as="image" href="/large.jpg" /> on current page
      B. Use <link rel="prefetch" href="/large.jpg" /> on current page and preload on next page
      C. Use <link rel="prefetch" href="/large.jpg" as="image" /> on current page
      D. Do not preload or prefetch; load image only when user clicks

      Solution

      1. Step 1: Understand prefetch for next page resources

        Prefetch loads resources in background for future use, ideal for next page images.
      2. Step 2: Combine with preload on next page

        Preloading on next page ensures immediate display when user arrives, improving UX.
      3. Step 3: Check invalid options

        Preload on current page wastes bandwidth if image not shown now; 'as' attribute invalid with prefetch; delaying load hurts UX.
      4. Final Answer:

        Use <link rel="prefetch" href="/large.jpg" /> on current page and preload on next page -> Option B
      5. Quick Check:

        Prefetch now + preload later = best for next page image [OK]
      Hint: Prefetch for next page, preload on arrival for speed [OK]
      Common Mistakes:
      • Preloading large images too early wasting bandwidth
      • Adding 'as' attribute to prefetch links
      • Not prefetching resources needed soon
      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