2012-01-13 174 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

相關問題