Compare commits

...

2 Commits

Author SHA1 Message Date
SlimusMinus
d09c2c71ce Merge pull request #107 from SlimusMinus/fix-fonts_loading
All checks were successful
deploy-frontend / deploy (push) Successful in 44s
Load Google Fonts and Yandex Maps without blocking app start
2026-10-20 23:46:20 +03:00
SlimusMinus
2af5f4acb9 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>
2026-10-20 23:44:50 +03:00
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/

View File

@@ -1,4 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');
/* Шрифты (Fraunces, Inter) подключаются в public/index.html */
/*
Design tokens live scoped to .nk-page so nothing outside this page

View File

@@ -1,4 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700;800;900&display=swap');
/* Шрифты подключаются без блокировки рендера в public/index.html */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

View File

@@ -1,5 +1,5 @@
/**
* public/index.html подключает API Яндекс.Карт через <script defer>,
* public/index.html подключает API Яндекс.Карт через <script async>,
* поэтому к моменту первого рендера window.ymaps может быть ещё undefined:
* скрипт не скачался, медленный CDN, блокировщик рекламы, офлайн.
*