Μετάβαση στο κύριο περιεχόμενο
← 📄 HTML & the platform·Ενότητα A7 · Μάθημα 3
ΕργασίαAdd three resource hints: preconnect 'https://cdn.example.com' (crossorigin), preload '/hero.webp' as='image' fetchpriority='high', preload '/inter.woff2' as='font' type='font/woff2' crossorigin.

προφόρτωση + προσύνδεση για κρίσιμους πόρους

100 XP7 min
Θεωρία

You saw this in A1 — now apply it in context

<head>
  <meta charset="utf-8" />

  <!-- 1. tell the browser about origins we'll fetch from -->
  <link rel="preconnect" href="https://cdn.example.com" crossorigin />
  <link rel="dns-prefetch" href="https://api.stripe.com" />

  <!-- 2. high-priority fetch the LCP image -->
  <link rel="preload" as="image" href="/hero.webp" fetchpriority="high" />

  <!-- 3. preload the hero font (so text doesn't FOUT) -->
  <link rel="preload" as="font" type="font/woff2" href="/inter.woff2" crossorigin />

  <!-- 4. let the parser proceed -->
  <link rel="stylesheet" href="/critical.css" />
  <script src="/app.js" defer></script>
</head>

When each is worth it

  • `preconnect` — when you'll fetch ≥1 thing from that origin within 5 seconds. Saves DNS + TCP + TLS handshake (~50-150ms on first request).
  • `dns-prefetch` — same idea, less expensive (DNS only), less reliable. Use when you MIGHT fetch from there.
  • `preload` — when a critical resource (LCP image, hero font, blocking JS module) is late-discovered. Lifts it to "highest priority" download queue.

Don't overdo preload

Every preload competes with your critical-path requests. Preload only the resource that's BLOCKING your LCP. Lighthouse warns: "Unused preload" if your preloaded thing isn't used within 3 seconds.

fetchpriority

A relatively new attribute. fetchpriority="high" on <link rel="preload"> AND on <img> lets you hint priority within the same resource type. Use on the hero image. Use low on offscreen images.

🔒

Εγγράψου για να αρχίσεις να προγραμματίζεις

Η θεωρία είναι ανοιχτή για όλους. Ο επεξεργαστής, η ζωντανή προεπισκόπηση και ο έλεγχος ξεκλειδώνουν με 7-ήμερη δωρεάν δοκιμή — απαιτείται κάρτα.

Εγγραφή — δωρεάν δοκιμή →

Τα πρώτα 10 μαθήματα κάθε διαδρομής είναι δωρεάν. Δεν χρειάζεται κάρτα.

← ΠροηγούμενοΕπόμενο μάθημα →

Μια συμβουλή Python ή web την ημέρα — με email

Σύντομο, γραμμένο στο χέρι, χωρίς spam. Διαγραφή με ένα κλικ.