views:

315

answers:

1

Im asking this here cause if i try more i think im going to lose my mind for sure
it seems i can't use php_value or php_flag but linking a php.ini using suPHP_ConfigPath works (for php files)
here's a list of stuff i tried in random order:

AddHandler application/x-httpd-php .otf
AddType
default_mimetype
application/vnd.oasis.opendocument.formula-template
auto_prepend_file = "otf.php"
zlib.output_compression = On
output_handler = ob_gzhandler
header("Content-type: application/octet-stream");

also renaming the .otf file to .php doesn't work either (all the php file on my server get gziped using zlib)
anyone got an idea? maybe an apache/php guru?
the answer is probably a mix of the list above but apparently im not doing it correctly

+4  A: 

With .htaccess, you could do like this, assuming font file is fontfile.otf.gz, browser request that as fontfile.otf

RewriteEngine On

#Check for browser's Accept-Encoding, remove it for force return gzipped one
RewriteCond "%{HTTP:Accept-Encoding}" "gzip.*deflate|deflate.*gzip"

#check file name is endswith otf
RewriteCond %{REQUEST_FILENAME} "\.(otf)$"

#check existance of .gz file name
RewriteCond %{REQUEST_FILENAME}.gz -s

#rewrite it to .otf.gz
RewriteRule ^.*$ %{REQUEST_URI}.gz [L]

#update some response header
<FilesMatch "\.otf\.gz$">
    AddEncoding gzip .gz
    ForceType "text/plain"
</FilesMatch>

And if font file and web site is cross-domain, you need to put Access-Control-Allow-Origin, firefox will not load font objects cross-domain.

In Gecko, web fonts are subject to the same domain restriction (font files must be on the same domain as the page using them), unless HTTP access controls are used to relax this restriction.

Header set Access-Control-Allow-Origin *
S.Mark
thx for answering // i copy pasted and tried it // it's not working (the font isn't getting gzipped) checking using firebug on firefox 3.5 // the forcetype isn't working either (application/vnd.oasis.opendocument.formula-template instead) // do i have to replace REQUEST_FILENAME or REQUEST_URI?
Knu
you have gzipped file made in advance, right? you can try removing accept-encoding check line by commenting out.
S.Mark
you can check out this page with firebug here - http://test.my-mm.org/font/embed.htm. its working and I am using similar way in my blog.
S.Mark
and if you are loading font cross-domain, you need to put Access-Control-Allow-Origin: * in header, updated my post too.
S.Mark
ok iv pre-gziped my font and it's working - THANK YOU! // but you didn't really answer the question (i wanted the server to gzip on the fly) // so if you don't mind ill let other users answer before accepting your solution // off topic - do you know a good gzipper(max compression)?
Knu
as far as i know, on the fly gzipping is done by mod gzip or mod deflate, you mentioned (no mod gzip or deflate) in title, may be thats why other people are not answering.
S.Mark
yes but there are still ob_gzhandler and zlib.output_compression (which are not modules you need to install)
Knu
I see, if you want specific answer for those method, you can raise new question and ask for "how to enable compression for font object using ob_gzhandler and zlib.output_compression",
S.Mark
ok ur right my question must have been badly formulated // btw the "text/plain" isn't really needed (replaced it by application/vnd.oasis.opendocument.formula-template) // ill accept your alternative answer
Knu