Перейти к основному содержимому
Frontend — это бесплатный бонус CodeMentor AI; основной продукт — Python. Зарегистрируйся, чтобы сохранить прогресс и открыть все 299 уроков фронтенда + 1,100+ уроков Python.Зарегистрироваться — бесплатно
← 📄 HTML & the platform·Модуль A1 · Урок 6
ЗаданиеIn the head, add three resource hints: preconnect to https://api.stripe.com (with crossorigin), preload the font /fonts/inter.woff2 (type='font/woff2', crossorigin, as='font'), and dns-prefetch to https://cdn.jsdelivr.net.

предварительная загрузка и предварительная выборка: сообщает браузеру, что вам нужно

100 XP9 minFREE
Теория

The browser is conservative — sometimes too much

When the parser hits <link rel="stylesheet" href="…">, it pauses page rendering until that file downloads. If your hero font is loaded via CSS, the page renders, *then* discovers the font, *then* downloads it — you see a flash of unstyled text for 200-800ms.

You can hint earlier:

<!-- load this NOW, in parallel with the HTML — high priority -->
<link rel="preload" as="font" href="/fonts/inter.woff2" type="font/woff2" crossorigin />

<!-- I'll probably need this on the next page — fetch when idle -->
<link rel="prefetch" href="/dashboard.html" />

<!-- this origin will get requests soon — open the TCP socket now -->
<link rel="preconnect" href="https://api.stripe.com" crossorigin />
<link rel="dns-prefetch" href="https://cdn.jsdelivr.net" />

Which one when

HintWhenCost
preconnectYou'll fetch from an origin in <5sTCP handshake (~50ms)
dns-prefetchSame, lower priority (cheaper, less reliable)DNS only (~10ms)
preloadA resource on THIS page that's currently late-discoveredFull download
prefetchA resource for the LIKELY-NEXT pageFull download (low priority)
modulepreloadAn ES module on this pageFull download + parse

Don't overdo it

Every preload competes with critical-path resources. Preload only what's actually causing a noticeable flash. Lighthouse will warn you ("Unused preload: never used within 3s").

Живой просмотр
← НазадСледующий урок →

Получай один совет по Python или веб-разработке — каждый день в почте

Коротко, без воды, без спама. Отписаться — в один клик.