Is it possible to DEFLATE a .woff2 file in .htaccess in nginx?

435 Views Asked by At

I have the following in my global .htaccess file on my nginx server:

# COMPRESS FILES

<IfModule mod_deflate.c>
  
  [...]

  AddOutputFilterByType DEFLATE application/font-woff2
  AddOutputFilterByType DEFLATE font/woff2

  [...]

</IfModule>

I understand there was some controversy a while back over what MIME Type should represent .woff2 files, but I was hoping that one of these lines:

  • application/font-woff2
  • font/woff2

would work.

Apparently, neither does.


Further Info:

  • I don't have any deeper .htaccess files overriding the global .htaccess file
  • My server version is nginx/1.21.6 (on this basis, I've never really understood how .htaccess directives work at all, but I use a good handful of modules and all the directives work)

Question:

Am I using the wrong MIME Type?

Or is the issue likely to be nginx related?

(Or something else which hasn't crossed my mind yet...) ?

1

There are 1 best solutions below

1
Irshad On

Most probably you shall modify nginx.conf file to add the required compression.

.htaccess file will not work in NGINX

To have better coverage on compression and performance over NGINX, you may use pagespeed module

https://developers.google.com/speed/pagespeed/module

Example code block for nginx.conf file

gzip on;
gzip_vary on;
zip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;

gzip_types
  font/eot
  font/otf
  font/ttf
  image/svg+xml
  text/css
  text/javascript
  text/plain
  text/xml;