#font-face - Fonts Not Requested by Browser, Not Loading - css

I'm attempting to load 4 fonts using #font-face as critical styles in the header for above-the-fold content, within <style> tags.
Rubik-Bold
Rubik-Italic
Rubik-LightItalic
Rubik-Regular
From what I can tell this should be correct, however only the first in the list loads. If I removed the first one, the next-in-line will be the first to load.
HTML:
#font-face {
font-family: 'Rubik';
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Bold.eot?2568338257603816725');
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Bold.eot?2568338257603816725#iefix') format("embedded-opentype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Bold.woff?2568338257603816725') format("woff"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Bold.woff2?2568338257603816725') format("woff2"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Bold.ttf?2568338257603816725') format("truetype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Bold.svg?2568338257603816725#timber-icons') format("svg");
font-weight: 700;
font-style: normal;
};
#font-face {
font-family: 'Rubik';
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Italic.eot?2568338257603816725');
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Italic.eot?2568338257603816725#iefix') format("embedded-opentype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Italic.woff?2568338257603816725') format("woff"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Italic.woff2?2568338257603816725') format("woff2"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Italic.ttf?2568338257603816725') format("truetype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Italic.svg?2568338257603816725#timber-icons') format("svg");
font-weight: 400;
font-style: italic;
};
#font-face {
font-family: 'Rubik';
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-LightItalic.eot?2568338257603816725');
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-LightItalic.eot?2568338257603816725#iefix') format("embedded-opentype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-LightItalic.woff?2568338257603816725') format("woff"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-LightItalic.woff2?2568338257603816725') format("woff2"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-LightItalic.ttf?2568338257603816725') format("truetype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-LightItalic.svg?2568338257603816725#timber-icons') format("svg");
font-weight: 300;
font-style: italic;
};
#font-face {
font-family: 'Rubik';
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Regular.eot?2568338257603816725');
src: url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Regular.eot?2568338257603816725#iefix') format("embedded-opentype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Regular.woff?2568338257603816725') format("woff"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Regular.woff2?2568338257603816725') format("woff2"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Regular.ttf?2568338257603816725') format("truetype"),
url('//cdn.shopify.com/s/files/1/1735/6971/t/25/assets/Rubik-Regular.svg?2568338257603816725#timber-icons') format("svg");
font-weight: 400;
font-style: normal;
};
This is what I get in Chrome's inspector:
Things I've tried based on similar threads I've read:
Eliminated all whitespace and put each #font-face on one line (solved the issue in another thread).
Tested the links that Shopify's CDN outputs, and they do work.
On the page, in the header:
HTML:
<div class="gift-line show-for-large">
<span>The Gift Line</span><span class="phone-number">XXX-XXX-XXXX</span>
</div>
And CSS, loaded before the font-face declarations (span should be inheriting this rule and therefore Rubik-Regular should be downloading):
body {
font-family: "Rubik", sans-serif;
font-weight: normal;
font-style: normal;
}
So in this case, I know that at least Rubik-Regular should be called in addition to Rubik-Bold. (There are no
Any suggestions? Thanks

Browsers try to minimize network connections by analizing your css and html to determine what font files you end up using and only download those.
Since you're using the same font-family name here you have to make sure you use each style combination of font-weight and font-style on the page for the browser to download all of them.
Also don't be tricked by some of the caching smarts browser put into place. Font's are cached quickly to prevent http requests.
I suggest you ignore the network traffic and inspect your element that is supposed to get the font and look at the computed tab.
For more information around how to debug fonts have a look at this short article by Paul Irish.

Related

How to solve the problem of caching fonts and files in css?

I use the font icon to display the icons, but when I update the fonts and add a new icon to the font, because the fonts are cached, they are difficult to display and the cache must be emptied.
How can I solve this problem?
You can use sass in your source. Use its Random() feature, as follows:
Every time the source is built, its version will be changed and the browser will call it without cache.
$version: random(9999);
$path: /YOUR_FOTNS_PATH
#font-face {
font-family: "font-icon";
src: url("#{$path}/fonticon.eot?v=#{$version}");
src: url("#{$path}/fonticon.eot?#iefix&v=#{$version}")
format("embedded-opentype"),
url("#{$path}/fonticon.ttf?v=#{$version}") format("truetype"),
url("#{$path}/fonticon.woff?v=#{$version}") format("woff"),
url("#{$path}/fonticon.svg?#afam&v=#{$version}") format("svg");
font-weight: normal;
font-style: normal;
font-display: block;
}
Your generated css will be:
#font-face {
font-family: "font-icon";
src: url('fonticon.eot?v=3889');
src: url('fonticon.eot?#iefix&v=3889') format("embedded-opentype"), url('fonticon.ttf?v=3889') format("truetype"), url('fonticon.woff?v=3889') format("woff"), url('fonticon.svg?#afam&v=3889') format("svg");
font-weight: normal;
font-style: normal;
font-display: block;
}

Custom fonts not loading on other people's server

I am running the Joints-WP-CSS version 6 theme which uses Foundation.
I have #font-face’d the following fonts in my style.css file like below. However, I am the only person who can see the proper fonts (here is a screenshot: http://erinstruble.com/wp-content/uploads/2020/03/Screen-Shot-2020-03-09-at-13.16.36.png). Other people are getting the fallbacks. Someone at Go-Daddy said they saw this error “DevTools failed to parse SourceMap: http://erinstruble.com/wp-content/themes/JointsWP-CSS-master/assets/styles/style.css.map”. How can I get these fonts to work properly for others?
#font-face {
font-family: "StudioFeixenSans-Book" !important;
src: url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSans-Book.eot")!important;
src: url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSans-Book.eot") format("embedded-opentype"),
url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSans-Book.woff2") format("woff2"),
url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSans-Book.woff") format("woff"),
url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSans-Book.ttf") format("truetype")!important;
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "StudioFeixenSerif-Regular"!important;
src: url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSerif-Regular.eot")!important;
src: url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSerif-Regular.eot") format("embedded-opentype"),
url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSerif-Regular.woff2") format("woff2"),
url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSerif-Regular.woff") format("woff"),
url("http://miyfood.com/home/erinstruble/public_html/erinstruble.com/wp-admin/css/webfont/StudioFeixenSerif-Regular.ttf") format("truetype")!important;
font-weight: normal;
font-style: normal;
}

Safari giving precedence to installed font

Some of the designers working at my workplace noticed that on Safari the font of our website appeared to be the one installed on their machine and not the one we are serving.
We noticed it in two different occasions and with two different fonts: Montserrat and Open Sans.
The first time (with Montserrat) the user had a newer version of the font, and she saw the newest only on Safari, because she had installed it on her local machine (this wasn't happening on Chrome).
The second time (with Open Sans) we saw a bolder font only on a particular machine: we then discovered that on that machine the user had installed a bolder weight (700) than the one we were serving (600). And the rule was
font-weight: bold;
so I suppose that the browser picked up the boldest (700) from the installed fonts.
I did some research but didn't find any evidence of this. Does anyone know if there is any evidence/documentation on Safari giving precedence to installed fonts instead of the ones you are serving?
We are not using Google Fonts from Google's CDN, as we decided to download them and serve them from our own server.
EDIT: I'm adding the code we use to load the font (generated using Google Webfonts Helper):
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url("font/opensans/open-sans-latin_cyrillic-400.eot");
src: local("Open Sans"), local("OpenSans"), url("font/opensans/open-sans-latin_cyrillic-400.eot?#iefix") format("embedded-opentype"), url("font/opensans/open-sans-latin_cyrillic-400.woff2") format("woff2"), url("font/opensans/open-sans-latin_cyrillic-400.woff") format("woff"), url("font/opensans/open-sans-latin_cyrillic-400.ttf") format("truetype"), url("font/opensans/open-sans-latin_cyrillic-400.svg#OpenSans") format("svg");
}
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 600;
src: url("font/opensans/open-sans-latin_cyrillic-600.eot");
src: local("Open Sans Semibold"), local("OpenSans-Semibold"), url("font/opensans/open-sans-latin_cyrillic-600.eot?#iefix") format("embedded-opentype"), url("font/opensans/open-sans-latin_cyrillic-600.woff2") format("woff2"), url("font/opensans/open-sans-latin_cyrillic-600.woff") format("woff"), url("font/opensans/open-sans-latin_cyrillic-600.ttf") format("truetype"), url("font/opensans/open-sans-latin_cyrillic-600.svg#OpenSans") format("svg");
}
#font-face {
font-family: 'Montserrat';
font-style: normal;
font-weight: 400;
src: url("font/montserrat/montserrat-latin-regular.eot");
src: local("Montserrat-Regular"), url("font/montserrat/montserrat-latin-regular.eot?#iefix") format("embedded-opentype"), url("font/montserrat/montserrat-latin-regular.woff2") format("woff2"), url("font/montserrat/montserrat-latin-regular.woff") format("woff"), url("font/montserrat/montserrat-latin-regular.ttf") format("truetype"), url("font/montserrat/montserrat-latin-regular.svg#Montserrat") format("svg");
}
#font-face {
font-family: 'Montserrat';
font-style: normal;
font-weight: 700;
src: url("font/montserrat/montserrat-latin-700.eot");
src: local("Montserrat-Bold"), url("font/montserrat/montserrat-latin-700.eot?#iefix") format("embedded-opentype"), url("font/montserrat/montserrat-latin-700.woff2") format("woff2"), url("font/montserrat/montserrat-latin-700.woff") format("woff"), url("font/montserrat/montserrat-latin-700.ttf") format("truetype"), url("font/montserrat/montserrat-latin-700.svg#Montserrat") format("svg");
}
And the relevant code to give a different font-face to different parts of the pages.
body{
font-family: "Open Sans", Helvetica, Arial, sans-serif;
font-size: 14px;
}
h6, h5, h4, h3, h2, h1{
font-family: inherit; // inheriting from body
font-weight: bold;
}
.view{
font-family: 'Montserrat', sans-serif;
}
Based on the code you show the solution is kind of obvious: if you don't want local fonts to interfere, don't tell the browser to try local() first. Or at all, really.
It's 2017, and in today's browser landscape you only want src: url(woff font version) format("woff"), nothing else: no other formats, no local-first, just explicitly the font your content should use. In the current browser landscape eot and svg don't even exist as valid formats anymore, and woff are ttf/otf, but with compression, and marked explicitly as intended "for the web" so that some normally required data can be left off, yielding an even smaller font payload. The only other format you might add is WOFF2, which uses a newer compression algorithm and allows "slicing" up a single font into several subsets so that the browser only loads the slices it needs to style your content instead of an entire font in one go.
Whatever generated this CSS for you appears to still be stuck in "how webfonts worked in 2012".
Eventually I used what #Mike'Pomax'Kamermans suggested in one of the last comments to his own answer, I'm posting it here just for clarity.
We removed every local specification and every src apart from the .eot file and the .woff2 file.
Then we added this declaration to tell Safari that our bold font should render with the 600 weight, otherwise Safari would look into the installed copy of the font (which included the 700 weight).
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: bold;
src: url('font/open-sans-latin_cyrillic_latin-ext-600.eot'); /* IE9 Compat Modes */
src: url('font/open-sans-latin_cyrillic_latin-ext-600.woff2') format('woff2'); /* Super Modern Browsers */
}

Load different font for different languages in SCSS

How do i utilize SCSS feature to load different font based on different language by using &:lang() in css?
I am planning to use it this way at top scss file chain. Do you think this is correct?
//Default font-family it's not Japan language
#font-face {
font-family: "xxx";
font-style: normal;
font-weight: normal;
src: url('xxx.eot');
src: local(xxx),
url("xxx.eot?#iefix") format("embedded-opentype"),
url("xxx.woff") format("woff"),
url("xxx.ttf") format("truetype"),
url("xxx.otf") format("opentype"),
url("xxx.svg#xxx") format("svg");
}
//If Japanese then
html:lang(ja) {
#font-face {
font-family: "Meiryo";
font-style: normal;
font-weight: normal;
src: url('Meiryo.eot');
src: local(Meiryo),
url("Meiryo.eot?#iefix") format("embedded-opentype"),
url("Meiryo.woff") format("woff"),
url("Meiryo.ttf") format("truetype"),
url("Meiryo.otf") format("opentype"),
url("Meiryo.svg#Meiryo") format("svg");
}
}
EDIT: the above code prints out like this without any error. This should have been a bug from scss
#font-face {
html:lang(jp) {
font-family: "Meiryo";
....
}
}
EDIT: it looks like unicode range is the solution. I'd love to know If you have any better solution. Thanks
https://developer.mozilla.org/en-US/docs/Web/CSS/#font-face/unicode-range
//If Japanese then
#font-face {
.......
unicode-range: 3000-303f;
}
The unicode-range CSS descriptor sets the specific range of characters to be used from a font defined by #font-face and made available for use on the current page. If the page doesn't use any character in this range, the font is not downloaded; if it uses at least one, the whole font is downloaded.

#font-face issues in Firefox/Mac & iPad

I have a few weird issues I need to solve.
First, let me show my #font-face declarations in my CSS file.
#font-face {
font-family: "Conv_Gotham-Book";
src: url("fonts/Gotham-Book.eot");
src: local("☺"),
url("fonts/Gotham-Book.woff") format("woff"),
url("fonts/Gotham-Book.ttf") format("truetype"),
url("fonts/Gotham-Book.svg#Gotham-Book") format("svg");
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "Conv_Gotham-Light";
src: url("fonts/Gotham-Light.eot");
src: local("☺"),
url("fonts/Gotham-Light.woff") format("woff"),
url("fonts/Gotham-Light.ttf") format("truetype"),
url("fonts/Gotham-Light.svg#Gotham-Light") format("svg");
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "Conv_Gotham-Medium";
src: url("fonts/Gotham-Medium.eot");
src: local("☺"),
url("fonts/Gotham-Medium.woff") format("woff"),
url("fonts/Gotham-Medium.ttf") format("truetype"),
url("fonts/Gotham-Medium.svg#Gotham-Medium") format("svg");
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "Conv_Gotham-Bold";
src: url("fonts/Gotham-Bold.eot") format("eot");
src: local("☺"),
url("fonts/Gotham-Bold.woff") format("woff"),
url("fonts/Gotham-Bold.ttf") format("truetype"),
url("fonts/Gotham-Bold.svg#GothamBold") format("svg");
font-weight: normal;
font-style: normal;
}
Problems: Hyperlinks using any of those custom fonts don't work in only one browser/platform combination Firefox 13.0.1/Mac (Example here: http://lonely-dev.com/leapfrogbeta/?page_id=896 on the headlines, )
Second Problem: Font disappears on iPad2/Safari browser.
Everything else is fine, would love some insight.
You have declared to use a font called "Journal" in your css for .custom .headline_area h2 a in custom.css while in the above code example you're calling for the Gotham Family (which, btw, has no web license at the moment). Journal is loaded correctly in both Firefox/Mac and iPad/Safari. Links work in both.
Update: the font loads fine in all mentioned cases but the links aren't working. This is because of a being an inline element. Also, declaring a height for the heading a is a bad idea. Just use this rule:
.custom .headline_area h2 a {
display: block;
}
and the links will work.
Another thing is that you should declare the heading font on the h1, h2 etc. and not just on their contained links.

Resources