I use GZip compression on my site and this works for all files but it is not currently compressing fonts.

Can you tell me what is wrong with the below .htaccess code ?

<ifModule mod_gzip.c>
  <ifmodule mod_mime.c> 
    Addtype font/opentype .otf
    Addtype font/eot .eot
    Addtype font/truetype .ttf
  </ifmodule>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl|ttf|eot|otf)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<ifModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript font/opentype font/truetype font/eot
</ifModule>

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>

<ifModule mod_headers.c>
  Header unset ETag
</ifModule>

FileETag None

<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>

AddType text/cache-manifest .manifest
  • I've not played with font gzipping before, you might want to take a look at the answer of this stackoverflow.com post. http://stackoverflow.com/questions/2042052/ o.k.w almost 7 years ago

2 answers

0
points
This was chosen as the best answer

I managed to get gzip working this.

I added the following (in place of the mod_deflate stuff above):

<ifmodule mod_deflate.c>
<ifmodule mod_mime.c>
Addtype font/opentype .otf
Addtype font/eot .eot
Addtype font/truetype .ttf
</ifmodule>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css   application/x-javascript application/javascript text/text font/opentype font/truetype font/eot
</ifmodule>

Thanks for your responses.

Answered over 6 years ago by Shaun Robinson
1
point

Lines 3-5: s/Addtype/AddType/g

If that doesn't change anything (which I assume): Since you already defined MIME types for fonts, does GZipping work, if you add this line?

 mod_gzip_item_include mime ^font/.*

If not, can you verify, that this line of yours works for any of the other types, like HTML?

mod_gzip_item_include file \.(html?|txt|css|js|php|pl|ttf|eot|otf)$

(It's a bit tricky, because you define extra rules below for any of those except the fonts. You'd have to disable those temporarily.)

Answered over 6 years ago by Boldewyn