Load Google Fonts and Yandex Maps without blocking app start

The fonts were pulled by @import inside the main CSS bundle; the deferred app
bundle waited for that stylesheet, so a slow fonts.googleapis.com kept the page
blank for 20-30 s. Fonts now load from index.html as a print stylesheet switched
on by onload (text renders with a fallback font meanwhile, display=swap).

The Maps API script was defer, so the app bundle (deferred after it) could not
run until the Maps API downloaded. It is async now; map code already waits for
window.ymaps via whenYmapsReady.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-20 23:44:50 +03:00
parent d53174a1cf
commit 2af5f4acb9
4 changed files with 20 additions and 4 deletions

View File

@@ -12,7 +12,23 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/apple-touch-icon.png" />
<script defer src="https://api-maps.yandex.ru/2.1/?apikey=%REACT_APP_YANDEX_MAPS_KEY%&lang=ru_RU" type="text/javascript"></script>
<!--
Шрифты Google — без блокировки рендера. Раньше они подключались через
@import в CSS-бандле: бандл приложения (defer) ждал этот CSS, и при
медленном или недоступном fonts.googleapis.com страница оставалась белой
20–30 секунд. Теперь стили грузятся как media="print" и включаются по
onload; до этого текст рисуется системным шрифтом (display=swap).
-->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700;800;900&amp;family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&amp;family=Inter:wght@400;500;600;700&amp;display=swap" media="print" onload="this.media='all'" />
<noscript><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700;800;900&amp;family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&amp;family=Inter:wght@400;500;600;700&amp;display=swap" /></noscript>
<!--
API Яндекс.Карт — async, а не defer: defer-скрипты выполняются по порядку,
и бандл приложения ждал бы загрузку карт. Код карты сам дожидается
window.ymaps (src/utils/ymapsApi.js → whenYmapsReady).
-->
<script async src="https://api-maps.yandex.ru/2.1/?apikey=%REACT_APP_YANDEX_MAPS_KEY%&lang=ru_RU" type="text/javascript"></script>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/