Skip to content

Update MIME types associated to font extensions .ttf, .woff, .woff2, and .otf#2065

Merged
ioquatix merged 4 commits into
rack:mainfrom
davidstosik:sto/font-mime
Apr 3, 2023
Merged

Update MIME types associated to font extensions .ttf, .woff, .woff2, and .otf#2065
ioquatix merged 4 commits into
rack:mainfrom
davidstosik:sto/font-mime

Conversation

@davidstosik

@davidstosik davidstosik commented Mar 27, 2023

Copy link
Copy Markdown
Contributor

What?

This PR updates the MIME types associated to font file extensions .ttf, .woff, .woff2, and .otf to the more recent types prefixed with font/.

Why?

Working on deploying a simple Rails application to Fly.io, I noticed that even though it was serving most of my assets gzipped (content-encoding: gzip), the TTF font that it serves was desperately uncompressed (and heavy!).
It turns out that, as a precompiled asset, it gets served with the header content-type: application/octet-stream, and I believe this is due to Rack's MIME types.
I believe this content-type might be excluded from getting gzipped by Fly.io's reverse proxy (and maybe other hosting solutions too?).

Looking into it, I noticed that .woff and .woff2 were using deprecated MIME types and decided to update them too.

How?

Simply updated the values in Rack's hash that associates file extensions to MIME types.

Anything Else?

Resources on the IANA website:

  • font/woff:

    File extension(s): woff
    (...)
    Deprecated Alias: The existing registration "application/font-woff" is deprecated in favor of "font/woff".

  • font/woff2:

    File extension(s): woff2

  • font/ttf:

    File extension(s): Font file extensions used for TrueType / OFF / OpenType fonts: .ttf and .otf

Note that it might be worth revisiting the .otf too, but I was unable to find clear information about this extension. (font/otf exists, but the .otf extension is also associated with application/vnd.oasis.opendocument.formula-template.)

".otf" => "application/vnd.oasis.opendocument.formula-template",

For reference, I added this to my Rails application's config/initializers/assets.rb, as a temporary workaround:

Rack::Mime::MIME_TYPES[".ttf"] = "font/ttf"

@davidstosik davidstosik changed the title Update mime-types associated to font extensions .ttf, .woff and .woff2 Update MIME types associated to font extensions .ttf, .woff and .woff2 Mar 27, 2023
@ioquatix

Copy link
Copy Markdown
Member

Regarding otf, what does the Ruby mime-types gem say about it? I find that is a good source of truth.

@davidstosik

davidstosik commented Mar 28, 2023

Copy link
Copy Markdown
Contributor Author

@ioquatix .otf seems to be associated to the font type:

- !ruby/object:MIME::Type
  content-type: font/otf
  encoding: base64
  extensions:
  - otf
  xrefs:
    rfc:
    - rfc8081
    template:
    - font/otf
  registered: true

It also looks like application/vnd.oasis.opendocument.formula-template is associated with extensions .odf and .odft.

@simi

simi commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

To make (web)fonts support complete, what about eot? Not sure what's the adoption today, but it was popular earlier due to IE.

@ioquatix

Copy link
Copy Markdown
Member

I would be fine for .otf -> font/otf. That seems reasonable to me.

I don't have any opinion about eot. I suppose in order to keep the list "short", we try to only include relevant, modern, mime types. So, I guess on that bases, if eot is no longer in common usage, I'd suggest we don't add it.

@ioquatix

ioquatix commented Apr 2, 2023

Copy link
Copy Markdown
Member

@davidstosik will you update the PR and add .otf?

@davidstosik

davidstosik commented Apr 2, 2023

Copy link
Copy Markdown
Contributor Author

Sure!

(By the way, .eot is in there already, mapped to application/vnd.ms-fontobject. font/eot does not seem to be a thing, so there's nothing to change for this one.)

@davidstosik davidstosik changed the title Update MIME types associated to font extensions .ttf, .woff and .woff2 Update MIME types associated to font extensions .ttf, .woff, .woff2, and .otf Apr 2, 2023
@ioquatix

ioquatix commented Apr 2, 2023

Copy link
Copy Markdown
Member

@davidstosik Do you mind adding an entry to the changelog, thanks!

@davidstosik davidstosik force-pushed the sto/font-mime branch 2 times, most recently from a86ce01 to c1f7339 Compare April 3, 2023 01:47
@davidstosik

Copy link
Copy Markdown
Contributor Author

Done! Am I supposed to add my GitHub handle, or is that reserved to maintainers?

@ioquatix

ioquatix commented Apr 3, 2023

Copy link
Copy Markdown
Member

You can add it.

@ioquatix ioquatix merged commit f5666bc into rack:main Apr 3, 2023
@davidstosik davidstosik deleted the sto/font-mime branch April 10, 2023 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants