2012-01-13 117 views
3

当我的站点加载时,浏览器显示用字体表示的文本(立即显示带有宋体字体的文本)之前几秒钟会冻结。字体会导致性能问题

我一直在接受来自用户的投诉,体验冻结时间长达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

字体的大小是什么?哪些浏览器遇到您描述的问题? – c69 2012-01-13 22:43:32

+0

实际上,它是铬的体验最滞后 – 2012-01-15 07:43:46

回答

5

尽量压缩和缓存的字体。如果您使用Apache,您可以使用.htaccess文件

下面是从性能专家史蒂夫海湾

附加信息和资源

非常helpful overview假设你使用Apache和模块配置此mod_expiresmod_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> 

添加ABO后一直到.htaccess,观察相关的头域来验证。

如果您有兴趣了解更多信息,请查看cache controlcompression的速度提示。

+0

“_Typekit显然是对某事 - 自定义字体的使用已在一年内增加了三倍。**我警告不要使用@ font-face出于性能原因**,但性能不是' (Gasp!)自定义字体显然具有对网站所有者有吸引力的美学效益。“[Steve Souders,2011年11月](http://www.stevesouders.com/blog/2011/11/17/添加你的网站自定义字体/) – c69 2012-01-13 22:49:40

+0

非常有趣的文章。我无法理解的是如何缓存字体文件? – 2012-01-15 07:43:02

+0

我已添加其他信息。祝你好运! – shaunsantacruz 2012-01-15 18:03:20

相关问题