292

Today I updated Font Awesome package to 4.3.0 and noticed that woff2 font was added. That file is linked in CSS so I need to configure nginx to serve woff2 files properly.

Currently I have this block in nginx config for fonts:

location ~* \.(otf|eot|woff|ttf)$ {
    types     {font/opentype otf;}
    types     {application/vnd.ms-fontobject eot;}
    types     {font/truetype ttf;}
    types     {application/font-woff woff;}
}

What is proper mime type for woff2 fonts?

Limon Monte
  • 44,025
  • 43
  • 163
  • 189
  • 1
    Here's how to cache woff2 files in Apache: ` AddType font/woff2 woff2` and ` ExpiresActive On ExpiresByType font/woff2 "access plus 1 month"`. (Closing tags and newlines omitted.) – Chloe Nov 24 '15 at 21:55

4 Answers4

462

In IIS you can declare the mime type for WOFF2 font files by adding the following to your project's web.config:

<system.webServer>
  <staticContent>
    <remove fileExtension=".woff2" />
    <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
  </staticContent>
</system.webServer>

Update: The mime type may be changing according to the latest W3C Editor's Draft WOFF2 spec. See Appendix A: Internet Media Type Registration section 6.5. WOFF 2.0 which states the latest proposed format is font/woff2

Steven Anderson
  • 7,810
  • 4
  • 22
  • 32
  • 6
    Now MIME-types in IIS 10 was support .woff2. With IIS 10 you don't need to change anything in web.config. – Kevin Nov 20 '15 at 07:36
  • 7
    What purpose does the `` tag serve here? It doesn't seem to be documented in the IIS reference (https://www.iis.net/configreference) – Pathogen Nov 23 '16 at 22:34
  • 19
    @Pathogen Sometimes IIS throws an error if the mimeMap already exists. Removing it before adding it fixes that error. – Allan Nov 30 '16 at 14:47
218

font/woff2

For nginx add the following to the mime.types file:

font/woff2 woff2;


Old Answer

The mime type (sometime written as mimetype) for WOFF2 fonts has been proposed as application/font-woff2.

Also, if you refer to the spec (http://dev.w3.org/webfonts/WOFF2/spec/) you will see that font/woff2 is being discussed. I suspect that the filal mime type for all fonts will eventually be the more logical font/* (font/ttf, font/woff2 etc)...

N.B. WOFF2 is still in 'Working Draft' status -- not yet adopted officially.

atwright147
  • 3,387
  • 4
  • 26
  • 52
  • 39
    This has been updated. The spec makes it very clear. Type is font and subtype is woff2 which makes is font/woff2. This is also what Google Fonts itself uses. – Raivo Laanemets Jun 22 '15 at 05:45
  • I still cannot see anything definitive in the spec. Though they do talk about wanting to introduce a `font/*` top level type. I think in the interests of full information, I will add that to my answer. – atwright147 Jun 22 '15 at 10:17
  • @atwright147 the mime types are covered in appendix A, for Woff2 it is section 6.5 of appendix A. – Richard Sep 03 '15 at 12:32
  • 3
    Updated March 2016: it is now a candidate recommendation and font/woff2 is the mimetype https://www.w3.org/TR/WOFF2/#IMT – Chris F Carroll May 12 '16 at 16:17
  • when I gzip woff2 the file gets larger - unlike my CSS and JS files which are shrunk massively - maybe its already compressed? – danday74 Nov 10 '20 at 01:16
38

Apache

In Apache, you can add the woff2 mime type via your .htaccess file as stated by this link.

AddType  application/font-woff2  .woff2

IIS

In IIS, simply add the following mimeMap tag into your web.config file inside the staticContent tag.

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
Fizzix
  • 20,849
  • 34
  • 100
  • 160
  • what about `application/x-font-woff2` – Nerdroid Aug 11 '15 at 05:05
  • 1
    Hey @Moes :) Acutally, `application/x-font-woff2` is the old type for when woff2 was very new. The [W3C Spec](http://www.w3.org/TR/WOFF/#appendix-b) now recommends using `application/font-woff2` since that is widely supported. If you're after backwards compatibility, feel free to also include `x-font-woff2`. – Fizzix Aug 18 '15 at 01:58
  • In IIS, be careful to remove any previously defined extension entries in case they are defined somewhere else in the server. This will give you *very* confusing errors if you encounter it! `` and then define it as above :) – jocull Apr 22 '16 at 15:13
  • Note that the proposed and also most probably be accepted is font/woff2 – Syakur Rahman Jun 05 '16 at 09:29
  • 1
    The [W3C Recommendation for WOFF File Format 2.0](https://www.w3.org/TR/WOFF2/#IMT) *now* recommend using `font/woff2` as the MIME type but the [IANA list of official media types](https://www.iana.org/assignments/media-types/media-types.xhtml) does not (yet) include WOFF2. – Anthony Geoghegan Nov 08 '16 at 18:15
17

http://dev.w3.org/webfonts/WOFF2/spec/#IMT

It seem that w3c switched it to font/woff2

I see there is some discussion about the proper mime type. In the link we read:

This document defines a top-level MIME type "font" ...

... the officially defined IANA subtypes such as "application/font-woff" ...

The members of the W3C WebFonts WG believe the use of "application" top-level type is not ideal.

and later

6.5. WOFF 2.0

    Type name:

        font
    Subtype name:

        woff2

So proposition from W3C differs from IANA.

We can see that it also differs from woff type: http://dev.w3.org/webfonts/WOFF/spec/#IMT where we read:

Type name:

    application
Subtype name:

    font-woff

which is

application/font-woff

http://www.w3.org/TR/WOFF/#appendix-b

Community
  • 1
  • 1
fantastory
  • 1,646
  • 19
  • 22
  • 1
    I don't see anything on that page to suggest that it has been changed to `font/woff2` can you calrify please? – atwright147 Apr 28 '15 at 13:30
  • Maybe I missunderstand it. I mean Appendix A, '6.5. WOFF 2.0' – fantastory Apr 28 '15 at 14:14
  • I've got to say the spec isn't very clear. I think they are referring to the `font-woff2` part – atwright147 Apr 29 '15 at 08:39
  • 1
    Can't imagine that this is downvoted. The spec makes it very clear. Type is font and subtype is woff2 which makes is font/woff2. This is also what Google Fonts itself uses. – Raivo Laanemets Jun 22 '15 at 05:43
  • Agreed, can't see why this was downvoted. Though the spec document has been updated since this question was asked/answered. – atwright147 Jun 22 '15 at 10:28
  • I think this answer is better and also more correct, than the accepted. Also I think all fonts should come under one primary type name: "font/..." – Vasil Popov Jul 23 '15 at 11:12
  • 2
    I upvoted this initially but and thought I could get a blog post out of this. As it stands this post is inline with the WOFF2 spec but that is still a *Working Draft* and hasn't been moved to *Recommendation Status* yet. This means woff2 doesn't technically have a mime as the `font/woff2` is invalid until it's approved but the spec document has revoked the endorsement of `application/font-woff2` leaving us with no official one. Therefore I think at this point I'm going to use `application/font-woff2`. – rtpHarry Aug 25 '15 at 20:21
  • 2
    @rtpHarry I previously upvoted both this answer and your comment. As of February 2017, the W3C published the *Standards Track* RFC 8081, making `font/woff2` the official media type. See https://stackoverflow.com/a/43321601/1640661 – Anthony Geoghegan Apr 10 '17 at 11:21