我正在使用@ font-face嵌入在TypeFront上託管的字體,但我的字體沒有被瀏覽器(Firefox 3.6.13和Epiphany 2.30.2)緩存。在每次頁面加載時,這都會導致Epiphany在Firefox和MFOMT(缺失文本的瞬間閃爍,我剛剛創建了一個)上出現FOUC(未定義內容的Flash)(我第一次使用FOUC/MFOMT頁面加載,但不是每次)。緩存字體字體
我試圖避免必須在CSS中嵌入字體,如果可能的話,我不能自己託管字體。
爲什麼字體沒有被緩存?有沒有其他的免費字體託管服務沒有這個問題?
測試頁:
<!DOCTYPE html>
<html>
<head>
<title>TypeFront Cache Test</title>
<style>
@font-face {
font-family: "Journal";
src: url("http://typefront.com/fonts/825588825.ttf") format("truetype");
}
h1 {
font-family: "Journal";
}
</style>
</head>
<body>
<h1>Test text</h1>
</body>
</html>
如果我在Firebug觀察,Net標籤顯示的字體被送達「200 OK」每一個頁面加載的時間,而不是「304未修改」或其他適應症正在使用緩存字體(例如,瀏覽器甚至不嘗試HTTP請求)。
HTTP標頭:
Response Headers
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 26 Feb 2011 12:57:18 GMT
Content-Type: font/ttf
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Status: 200 OK
Content-Transfer-Encoding: binary
Access-Control-Allow-Origin: *
Content-Disposition: attachment; filename="typefront_735a460727.ttf"
Cache-Control: max-age=31536000
Expires: Sun, 26 Feb 2012 12:57:18 GMT
Content-Encoding: gzip
Request Headers
GET /fonts/825588825.ttf HTTP/1.1
Host: typefront.com
User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Origin: null
請求中沒有if-modified-since標頭,所以服務器沒有選擇「未修改」的選項。問題在於客戶端:爲什麼它會發送請求,因爲將來會有Expires頭文件?爲什麼沒有if-modified-since標題和/或沒有If-None-Match標題?好的,可以這樣解釋,響應中沒有etag,所以它是基於時間戳的,但這應該足夠了,並且沒有Last-Modified,因此也沒有if-modified。但是,(遠)未來的頭文件也會阻止任何(第二)請求發生。 – 2011-02-26 13:52:08
我也在Firefox中使用MFOMT,但是,正如我注意到的,這是由於Firebug處於活動狀態。字體上沒有Firebug => 304(本地傳送)。 – Claudio 2011-05-24 11:54:10