Will a browser download a font-face even if it is

2019-01-26 09:45发布

It would be easier for development if I can just embed every typeface I'm likely to use, but I definitely don't want the extra HTTP requests for fonts that don't end up anywhere in the page. Can anyone enlighten me?

4条回答
Evening l夕情丶
2楼-- · 2019-01-26 10:16

Unfortunately, most browsers won't second guess you to avoid downloading fonts that aren't actually used (actually I don't know of any browser who is smart enough for such avoidance, which of course doesn't mean some such browsers might not exist). Couldn't you post-process the pages during deployment to remove the unused ones?

查看更多
时光不老,我们不散
3楼-- · 2019-01-26 10:27

in addition, you may do this too: clear browser cache, then run inspector of your browser (right click> Inpsect) and Debugger (resources) tab. then type the url and see what is being downloaded.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-26 10:32

Paul Irish has a really good tutorial on using @font-face

http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/

You can also use a syntax generator on fontsquirrel.com

查看更多
Luminary・发光体
5楼-- · 2019-01-26 10:34

IE will download the .eot file immediately when it encounters the @font-face declaration.

Gecko, Webkit, and Opera all wait until they encounter HTML that matches a CSS rule with a fontstack including the @font-face font.

-- http://paulirish.com/2009/fighting-the-font-face-fout/

So were it not for IE, it actually would be safe to embed lots of fonts, as long as you're careful not to refer to unused ones in your CSS styles, because at that point they will be downloaded by the browser.

查看更多
登录 后发表回答