0

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...) ?

Rounin
  • 27,134
  • 9
  • 83
  • 108
  • 3
    This is probably a rather pointless attempt to begin with - the woff2 format _is_ already compressed, see https://web.dev/reduce-webfont-size/#web-fonts-and-compression And compressing already compressed data a second time, usually gives very very little benefit. – CBroe Oct 11 '22 at 13:31
  • @CBroe - Ah... that's good to learn. Thanks. I did *not* know that `woff2` has **brotli** compression already built-in. In which case I agree with you - likely no need to attempt to `DEFLATE` at all. If you want to add that as an answer below, I will accept. Thank you. – Rounin Oct 11 '22 at 13:31
  • It is also pointless to attempt to configure Nginx using an `.htaccess` file. The file is only understood by and intended for an Apache web server. – Richard Smith Oct 11 '22 at 13:58
  • @RichardSmith - You'd certainly be forgiven for thinking so. I've always worked on the basis that this would be the case. So I have, to date, no explanation as to why all the `.htaccess` directives work on the `nginx` server. I can only guess that there must be some `nginx` module which can and does interpret `.htaccess` files - but if there is, I have yet to find it. – Rounin Oct 11 '22 at 14:33
  • Compression should be configured in your nginx.conf file. Use `nginx -T` (uppercase `T`) to view the entire configuration across all included files. – Richard Smith Oct 11 '22 at 15:08
  • I have no `nginx.conf` file. It's probably easier if we just pretend I have an Apache server. – Rounin Oct 11 '22 at 22:34

1 Answers1

1

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;
Irshad
  • 67
  • 6
  • Thank you, @Irshad. It's probably easier (for the purposes of this question) if we just pretend that I have an Apache server. – Rounin Oct 11 '22 at 22:34