Skip to content

Commit

Permalink
Add font MIME types per RFC 8081
Browse files Browse the repository at this point in the history
Closes #114.
  • Loading branch information
LeoColomb authored and mathiasbynens committed Sep 18, 2017
1 parent 208946a commit 20b446e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
18 changes: 5 additions & 13 deletions src/media_types/media_types.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,12 @@

# Web fonts

AddType application/font-woff woff
AddType application/font-woff2 woff2
AddType font/woff woff
AddType font/woff2 woff2
AddType application/vnd.ms-fontobject eot

# Browsers usually ignore the font media types and simply sniff
# the bytes to figure out the font type.
# https://mimesniff.spec.whatwg.org/#matching-a-font-type-pattern
#
# However, Blink and WebKit based browsers will show a warning
# in the console if the following font types are served with any
# other media types.

AddType application/x-font-ttf ttc ttf
AddType font/opentype otf
AddType font/ttf ttf
AddType font/collection ttc
AddType font/otf otf


# Other
Expand Down
3 changes: 3 additions & 0 deletions src/web_performance/compression.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/collection" \
"font/eot" \
"font/opentype" \
"font/otf" \
"font/ttf" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
Expand Down
6 changes: 6 additions & 0 deletions src/web_performance/expires_headers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@

# Web fonts

# Collection
ExpiresByType font/collection "access plus 1 month"

# Embedded OpenType (EOT)
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"

# OpenType
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/otf "access plus 1 month"

# TrueType
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/ttf "access plus 1 month"

# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 1 month"
Expand All @@ -96,6 +101,7 @@

# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType font/woff2 "access plus 1 month"


# Other
Expand Down
10 changes: 5 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ exports = module.exports = {
'test.otf': {
responseHeaders: {
'access-control-allow-origin': '*',
'content-type': 'font/opentype'
'content-type': 'font/otf'
}
},

Expand Down Expand Up @@ -436,14 +436,14 @@ exports = module.exports = {
'test.ttc': {
responseHeaders: {
'access-control-allow-origin': '*',
'content-type': 'application/x-font-ttf'
'content-type': 'font/collection'
}
},

'test.ttf': {
responseHeaders: {
'access-control-allow-origin': '*',
'content-type': 'application/x-font-ttf'
'content-type': 'font/ttf'
}
},

Expand Down Expand Up @@ -508,15 +508,15 @@ exports = module.exports = {
responseHeaders: {
'access-control-allow-origin': '*',
'content-encoding': null,
'content-type': 'application/font-woff'
'content-type': 'font/woff'
}
},

'test.woff2': {
responseHeaders: {
'access-control-allow-origin': '*',
'content-encoding': null,
'content-type': 'application/font-woff2'
'content-type': 'font/woff2'
}
},

Expand Down

0 comments on commit 20b446e

Please sign in to comment.