How Do We Tell Apache to Gzip Font Files?

Posted on 2011-10-22
Last Modified: 2012-05-12
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

Question by:Sivakatirswami
    LVL 19

    Expert Comment

    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/ = eot, application/vnd.oasis.opendocument.formula-template = otf, etc.)

    Author Comment

    OK... do you just add these lines like you have them above to httpd.conf, one line per file type?
    LVL 19

    Accepted Solution

    This actually looks cleaner, you could do this in one line according to

    # 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.

    Author Closing Comment

    Outstanding, Sorry for delay in responding... very busy here, but this is great thanks!
    LVL 19

    Expert Comment

    No problem, enjoy :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting ( to http…
    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now