当我的网站加载时,在浏览器显示使用font face呈现的文本之前会有几秒钟的冻结(带有arial字体的文本会立即显示)。
我一直在收到用户的投诉,这些用户的冻结时间长达10秒。
我该怎么办?
这是我插入字体的方式:
@font-face{
font-family:'GillSans';
src:url('../fonts/GIL_____.eot');
src:url('../fonts/GIL_____.eot?#iefix') format('embedded-opentype'),
url('../fonts/GIL_____.woff') format('woff'),
url('../fonts/GIL_____.ttf') format('truetype'),
url('../fonts/GIL_____.svg#GillSans') format('svg');
}
@font-face{
font-family:'GillSansB';
src:url('../fonts/GILB____.eot');
src:url('../fonts/GILB____.eot?#iefix') format('embedded-opentype'),
url('../fonts/GILB____.woff') format('woff'),
url('../fonts/GILB____.ttf') format('truetype'),
url('../fonts/GILB____.svg#GillSansB') format('svg');
}
@font-face{
font-family:'GillSansBI';
src:url('../fonts/GILBI___.eot');
src:url('../fonts/GILBI___.eot?#iefix') format('embedded-opentype'),
url('../fonts/GILBI___.woff') format('woff'),
url('../fonts/GILBI___.ttf') format('truetype'),
url('../fonts/GILBI___.svg#GillSansBI') format('svg');
}
@font-face{
font-family:'GillSansI';
src:url('../fonts/GILI____.eot');
src:url('../fonts/GILI____.eot?#iefix') format('embedded-opentype'),
url('../fonts/GILI____.woff') format('woff'),
url('../fonts/GILI____.ttf') format('truetype'),
url('../fonts/GILI____.svg#GillSansI') format('svg');
}
答案 0 :(得分:5)
尝试压缩和缓存字体。如果您使用Apache,则可以使用.htaccess
进行配置这是表演大师Steve Sounders的非常helpful overview
其他信息和资源
假设您使用Apache并且启用了模块mod_expires和mod_deflate,您可以将以下规则添加到.htaccess
<IfModule mod_expires.c>
Header set cache-control: public
ExpiresActive on
ExpiresByType font/ttf "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(ttf|otf|eot|svg)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
将以上内容添加到.htaccess后,请观察相关的标题字段以进行验证。
如果您有兴趣了解更多信息,请查看cache control和compression的速度提示。