Чтобы не мелькали шрифты в Хроме
Содержание
Описание задачи:
На страницах используются значки-иконки из Font Awesome. После того, как был подключен Cloudflare CDN, у локальных ресурсов вроде fontawesome.woff2 появились хедеры вроде vary:Accept-Encoding.

Вероятно, именно это привело к тому, что ресурсы fontawesome в Chrome v56, v57 (latest) перестали загружаться (from memory cache), а стали (from disk cache).
А это в свою очередь привело к тому, что иконки при переходах между страницами стали мерцать, сначала они не показываются. Их плейсхолдеры имеют не идеальную ширину, поэтому контент страницы при загрузке начал скакать.
Нужно, чтобы контент страницы не скакал, чтобы иконки показывались сразу. Чтобы было ощущение one-page-app, будто меняется только контент, но не меню и хедеры вокруг.
Причины:
В браузерах вроде FF или IE проблемы мерцания не наблюдается. Только в браузерах на движке хрома.
Хром обрабатывает директивы @font-face следующим образом: хотя содержимое и прочитано, указанные файлы не будут загружены вплоть до момента, пока данный шрифт не будет впервые использован. В моём случае, иконки font-awesome добавлялись только лишь через css-псевдоклассы :before и :after, вероятно поэтому браузер уже отрисовывал содержимое страницы, но шрифт, даже из дискового кеша, не успевал брать. Лишь из мемори кеша шрифт успевал браться, но этот тип кеша поломали заголовки cloudflare.
Шрифт «нигде не используется», браузер отрисовывает содержимое страницы, в процессе применения css обнаруживает, что шрифт всё-таки используется, но уже поздно. Происходит FOUC.
Не важно, что и шрифт, и все стили объявлены в <head>. Хром всё равно будет мелькать шрифтами.
Решение:
Решением могли бы быть:
а) всё-таки добиться опять попадания файла шрифта в chrome memory cache.
б) использовать элемент из этого шрифта нативно в теле страницы, а не через псевдоклассы.
Но мне это не подошло. Решение следующее:
preload
Приказываем браузеру пред-загрузить данный файл в память, вне зависимости от того, что он думает про свою оптимизацию.
|
1 2 3 4 5 6 7 8 9 |
// Preload font, prevent blinking FOUT. add_action('wp_head', function() { echo '<link rel="preload" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin="anonymous">'.PHP_EOL; }, 1); // Overwrite local font-face with CDN one. add_action('wp_head', function() { echo '<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">'.PHP_EOL; }); |
Теперь файл woff2 подгружается всегда, прежде чем начнётся отрисовка документа. Теперь даже если отключен кеш, иконки мелькать не будут, контент прыгать не будет.
Всё работает. Ура!
Обсуждение
Sprunki Incredibox truly elevates the music creation experience with its fresh beats and intuitive design. As a poker player, I appreciate the strategic depth and creativity it brings to the table. Check it out at Sprunki Incredibox.
I’ve played on OG777app for a while now. It’s convenient since it’s on my phone. Good when you’re on the go and bored. Give it a shot: og777app
Alright, so I stumbled upon j10gamedownload the other day. Looks like they got a bunch of game downloads. Gonna try one out later, hopefully no dodgy stuff! See for yourself j10gamedownload!
Aaajili36? Heard some good things about their promotions. I haven’t personally tried it, but a buddy of mine swears by it. Maybe worth checking out the bonuses. aaajili36
It’s fascinating how easily accessible online gaming has become, especially in places like the Philippines. The emphasis on secure platforms like jl16 slot & local payment options is smart-trust is huge when it comes to digital entertainment! It’s good to see responsible gaming gaining traction too.
Alright, champs! Checked out mu88ai. Decent selection of games and the site’s fairly straightforward. Could be worth a look if you’re bored. Check it out here: mu88ai
Barganhar plataforma, huh? Sounds Portuguese! Let’s see if I can snag a good deal here. Time to test my luck! barganhar plataforma
881jili https://www.881jili.org
2222ph https://www.be2222ph.org
luxebet88 https://www.laluxebet88.net
80jili https://www.be80jili.com
Tayabet: The Philippines’ Premier GCash Online Casino for Best Slots and Gambling. visit: tayabet
Yo, has anyone else been checking out 45678betvn? It’s got that Vietnamese feel to it, which is cool. The interface isn’t too shabby either. Give it a look if you’re looking to try something different. Here’s the link: 45678betvn
Just stumbled across aa8881 and decided to give it a whirl. Gotta say, the layout is pretty appealing. Let’s see how it goes! Check it out aa8881
Looking for some tips and tricks on some new games. Stumbled across blogmcgames.com. Hopefully, it’s got some strategy guides and insider info! Take a peek: blogmcgames
Pwede palang mag-login sa Nustar online using GCash? That’s awesome! So much easier to deposit and play. Galing talaga! Para sa atin to. nustar online gcash login
For all things ‘bong da net,’ this website is a winner. Simple layout, comprehensive content. I’m hooked! See for yourself: bong da net
Been trying out Slots VIP and am enjoying the selection of the games. Give it a look see slots vip