#t

1 messages · Page 1 of 1 (latest)

obsidian lantern
#

is it an overkill to config Astro prefetch if I am planning to prefetch only 3 links?

dull patrolBOT
#

Hi @obsidian lantern. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

It’s not overkill from Astro’s perspective, but it is optional.

Enabling prefetch is a single config flag plus adding data-astro-prefetch to the links you care about:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  prefetch: true, // or { defaultStrategy: 'hover' } etc.
});
<a href="/page-1" data-astro-prefetch>Page 1</a>
<a href="/page-2" data-astro-prefetch="viewport">Page 2</a>
<a href="/page-3" data-astro-prefetch="tap">Page 3</a>

Astro’s built‑in prefetching is explicitly designed to be opt‑in per link, so using it for only a few important links is a valid and supported use case. [Prefetch guide; Prefetch options]

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@obsidian lantern Kapa.ai is still learning and improving, please let me know how I did by reacting below.

obsidian lantern
#

@dull patrol it adds the script to every page, assess if it worth it:

| Metric | Value |
|---|---|
| Raw size | ~2 KB |
| Gzipped | ~900 bytes |
| Event listeners added | 5 (touchstart, mousedown, focusin, focusout, mouseenter per link) |
| IntersectionObserver | 1 instance created |
| DOM scan | All `<a>` tags scanned on every page |
| Parse + execute | Blocks main thread briefly |
dull patrolBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Astro’s docs don’t provide those exact metrics, but they do confirm that:

  • Enabling prefetch adds a prefetch script to every page. [Prefetch guide; Prefetch options]
  • That script is what powers data-astro-prefetch on your links.

Given that:

  • Your estimated script size (~900 B gzipped) is very small compared to typical page weight.
  • Astro is designed to be “fast by default” and still recommends prefetch as a way to improve perceived navigation speed. [Fast by default; Prefetch guide]

So even if you only prefetch 3 links, the trade‑off is usually favorable:

  • You pay: one small script on every page and a short main‑thread parse/execute.
  • You gain: much faster transitions for your 3 key routes, with built‑in handling for data‑saver/slow connections. [Prefetch strategies]

If those 3 links are important to your user flow (e.g. “Sign up”, “Checkout”, “Docs → Getting started”), it’s typically worth it. If they’re rarely used or non‑critical, you can skip prefetch and keep things even simpler.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@obsidian lantern Kapa.ai is still learning and improving, please let me know how I did by reacting below.

oblique apex