2012-03-06 14 views
2

私は、(deflateを使用していない)あらかじめ圧縮されたフォントを提供するためにApacheが必要です。Apache .htaccess:あらかじめ圧縮された@ font-faceフォントを提供する

/path_to /フォント/フォルダ内の私の.htaccessが

RewriteEngine On 
RewriteBase /path_to/fonts/ 
RewriteCond %{HTTP:Accept-Encoding} .*gzip.* 


RewriteRule (.*)\.ttf $1.ttf.gz 


AddEncoding x-gzip gz 

RemoveType application/x-gzip .gz 

レスポンスヘッダのように見える

Accept-Ranges bytes 
Connection Keep-Alive 
Content-Encoding **gzip** 
Content-Length **31709** 
Content-Type **text/plain** 
Date Tue, 06 Mar 2012 18:14:51 GMT 
Etag "7200000008e241-7bdd-4ba954a7395a8" 
Keep-Alive timeout=5, max=99 
Last-Modified Tue, 06 Mar 2012 16:11:08 GMT 
Server Apache/2.2.11 (Win32) PHP/5.2.9 
Vary Accept-Encoding 

コンテンツの長さが31709を圧縮サイズであろうと、述べていますが、私はそれをダウンロードすることができません。

ヒントを教えてください。

+0

text/plainのは間違ったMIMEタイプのようです。しかし、なぜ自分でgzippingを処理したいですか?サーバーでCPU使用率を節約する必要がありますか? – Gerben

+0

代わりにどのMIMEタイプを使用しますか? pre-gzippingはクライアントの必要条件です。 – Paco

+0

'font/ttf'か' application/x-font-ttf'を使います。 pre-gzippingは愚かな必要条件のように思えるかもしれませんが、恐らくどこかで[insert-buzzword-here] :-Pの方が良いと読める人が作っています。あなたがこの事を理解しようと費やした時間を見てください。非常に無駄に思える。ちょうど私の2セント。 – Gerben

答えて

0

私の解決策です。これは、ほとんどが少し磨かれています。

クライアントがgzipをサポートしていない限り、タイプとエンコーディングを設定しません。また、使用されているモジュールを宣言して、すべてのモジュールがサポートされていない場合は何も起こりません。

フォルダ構造:

fonts/ 
    Shanti-Regular.ttf.gz 
    Federo-Regular.ttf.gz 
    Shanti-Regular.ttf 
    Federo-Regular.ttf 
    .htaccess 

次に.htaccessファイルは含まれています

# Rewrite URLs to add gzipped version of font when it exits. 
<IfModule mod_rewrite.c> 
<IfModule mod_mime.c> 
    RewriteEngine on 

    #Serve gzip compressed TTF files if they exist and the client accepts gzip. 
    RewriteCond %{HTTP:Accept-encoding} gzip 
    RewriteCond %{REQUEST_FILENAME}\.gz -s 
    RewriteRule ^(.*)\.ttf $1\.ttf\.gz [QSA] 

    # update the response header of compressed file 
    # makes browser think mod_gzip did it. 
    <FilesMatch "\.ttf\.gz$"> 
    AddEncoding gzip .gz 
    ForceType "application/x-font-ttf" 
    </FilesMatch> 

</IfModule> 
</IfModule> 
関連する問題