• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1229
  • Last Modified:

How Do We Tell Apache to Gzip Font Files?

I want to enter the correct parameters to the httpd.conf file  to get Apache to gzip webfonts.

I already have this in the root httpd.conf for all domains on the box.  But webfonts have no established mime-type (that I know of... as of Feb 2011)  so how do you tell Apache to gzip all
*.eot *.otf *ttf *.woff *.svg web font files before filling the GET request?

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/x-httpd-php

  • 3
  • 2
1 Solution
You could do it by file extension instead of mime type:

mod_gzip_item_include file \.eot$
mod_gzip_item_include file \.otf$
mod_gzip_item_include file \.ttf$
mod_gzip_item_include file \.woff$
mod_gzip_item_include file \.svg$

BTW, there are mime types for a couple of these already, but seems like more work to do it that way (application/vnd.ms-fontobject = eot, application/vnd.oasis.opendocument.formula-template = otf, etc.)
SivakatirswamiAuthor Commented:
OK... do you just add these lines like you have them above to httpd.conf, one line per file type?
This actually looks cleaner, you could do this in one line according to http://www.helicontech.com/ape/doc/mod_gzip.htm

# By file extension
SetEnvIfNoCase request_uri \.mdb$ gzip=9
SetEnvIfNoCase request_uri \.bmp$ gzip cache-enable=mem
SetEnvIfNoCase request_uri \.(?:jpg|gif|png|swf|avi|rm)$ no-gzip                          

# By MIME type
SetEnvIfNoCase mime text/.* gzip=9 cache-enable=mem
SetEnvIfNoCase mime audio/wav gzip cache-enable=mem
SetEnvIfNoCase mime image/bmp gzip cache-enable=mem
SetEnvIfNoCase mime message/rfc822 gzip

So for yours, something like

SetEnvIfNoCase request_uri \.(?:eot|otf|ttf|woff||svg)$ gzip  

And yes, this should all go in httpd.conf - before you restart, run "httpd configtest" to make sure it likes the syntax.
SivakatirswamiAuthor Commented:
Outstanding, Sorry for delay in responding... very busy here, but this is great thanks!
No problem, enjoy :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now