Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@font-face is causing slow load times

Lately i started noticing the website loads very slow at some point.

I've investigated this with firebug and when the page takes very long to load this is showing up:

Firebug Net Inspection It seems totally random, but the requests to webfont.woff just waits and waits forever. If i try to reach this resourse manually, it works fine and responses within 100ms. The page i'm talking about is http://wtf.maikelzweerink.nl, and the custom fonts come from the main domain maikelzweerink.nl.

The face-fonts are declared at default.css, also from the main domain:

@font-face {
    font-family: 'Proximanova Regular';
    src: url('//maikelzweerink.nl/general/font/Proximanova-Regular/webfont.eot');
    src: url('//maikelzweerink.nl/general/font/Proximanova-Regular/webfont.eot?#iefix') format('embedded-opentype'),
         url('//maikelzweerink.nl/general/font/Proximanova-Regular/webfont.woff') format('woff'),
         url('//maikelzweerink.nl/general/font/Proximanova-Regular/webfont.ttf') format('truetype'),
         url('//maikelzweerink.nl/general/font/Proximanova-Regular/webfont.svg#ProximaNovaRgRegular') format('svg');
}

Even with the correct HTTP headers

In chrome the same deal (click for larger): Chrome time test

like image 469
user1226868 Avatar asked Sep 03 '12 17:09

user1226868


3 Answers

The MIME types are set to text/plain on the fonts, rather than what they should be.

In your .htaccess file (assuming Apache), add:

AddType application/vnd.ms-fontobject  eot
AddType application/x-font-ttf         ttf ttc
AddType font/opentype                  otf
AddType application/x-font-woff        woff

This will fix things, and make sure the fonts work in all browsers.

like image 195
Rich Bradshaw Avatar answered Nov 18 '22 16:11

Rich Bradshaw


You need to preload or prefetch your font like that

<link rel="preload" as="font" href="/fonts/Pacifico-Regular.ttf" type="font/ttf" crossorigin="anonymous">

more information How to load web fonts to avoid performance issues and speed up page loading

like image 42
Laurent Chaloupe Avatar answered Nov 18 '22 16:11

Laurent Chaloupe


I used base64 enconding to embed the font inside the CSS to reduce the amount of requests. The base64 has the downside of costing more initial bandwith but hey, it works! This fixed it.

Ofcourse i'm not really happy with a CSS file that is 180KB in size :/

Edit: It turned out to be the ISP that was the problem. When I mannualy loaded the font it retrieved it from cache (dammit chrome!). Somehow these fonts where not directly available on the ISP service and requests/reads from the harddisk would take a while.

like image 4
user1226868 Avatar answered Nov 18 '22 15:11

user1226868