Skip to content

Commit 6ce3707

Browse files
committed
Add configs for WOFF 2.0 font files (.woff2)
* Serve `.woff2` files with far-future expires headers and with the current specification suggested media type, namely `application/font-woff2` (note: this media type is not yet registered with IANA, however, things aren't likely to change). * Ensure that `.woff2` files aren't served with any of the `HTML` document related headers, and they are accessible even cross-domain. Node: There is no need to compress WOFF 2.0 fonts as they are already compressed! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Huge thanks to Vladimir Levantovsky for all his help! Ref: http://www.w3.org/TR/WOFF2/ #32 Close #32
1 parent bb33819 commit 6ce3707

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### HEAD
22

3+
* Add configs for WOFF 2.0 font files (`.woff2`)
4+
[[#32](https://github.com/h5bp/server-configs-apache/issues/32)].
35
* Add configs for GeoJSON files (`.geojson`)
46
[[16d3965](https://github.com/h5bp/server-configs-apache/commit/16d39657164a397c8584843296fa04dc297c4b55)].
57

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"server-configs-test": "https://github.com/h5bp/server-configs-test/tarball/0.1.0"
4+
"server-configs-test": "https://github.com/h5bp/server-configs-test/tarball/0.2.0"
55
},
66
"scripts": {
77
"test": "server-configs-test"

src/.htaccess

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# By default allow cross-origin access to web fonts.
2929

3030
<IfModule mod_headers.c>
31-
<FilesMatch "\.(eot|otf|tt[cf]|woff)$">
31+
<FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
3232
Header set Access-Control-Allow-Origin "*"
3333
</FilesMatch>
3434
</IfModule>
@@ -97,7 +97,7 @@ Options -MultiViews
9797
Header set X-UA-Compatible "IE=edge"
9898
# `mod_headers` cannot match based on the content-type, however, this header
9999
# should be send only for HTML documents and not for the other resources
100-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
100+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
101101
Header unset X-UA-Compatible
102102
</FilesMatch>
103103
</IfModule>
@@ -184,6 +184,7 @@ Options -MultiViews
184184

185185
# Web fonts
186186
AddType application/font-woff woff
187+
AddType application/font-woff2 woff2
187188
AddType application/vnd.ms-fontobject eot
188189

189190
# Browsers usually ignore the font media types and simply sniff
@@ -331,7 +332,7 @@ AddDefaultCharset utf-8
331332

332333
# <IfModule mod_headers.c>
333334
# Header set X-Frame-Options "DENY"
334-
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
335+
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
335336
# Header unset X-Frame-Options
336337
# </FilesMatch>
337338
# </IfModule>
@@ -356,7 +357,7 @@ AddDefaultCharset utf-8
356357

357358
# <IfModule mod_headers.c>
358359
# Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
359-
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
360+
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
360361
# Header unset Content-Security-Policy
361362
# </FilesMatch>
362363
# </IfModule>
@@ -486,7 +487,7 @@ AddDefaultCharset utf-8
486487
# <IfModule mod_headers.c>
487488
# # (1) (2)
488489
# Header set X-XSS-Protection "1; mode=block"
489-
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
490+
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
490491
# Header unset X-XSS-Protection
491492
# </FilesMatch>
492493
# </IfModule>
@@ -689,6 +690,7 @@ FileETag None
689690

690691
# Web fonts
691692
ExpiresByType application/font-woff "access plus 1 month"
693+
ExpiresByType application/font-woff2 "access plus 1 month"
692694
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
693695
ExpiresByType application/x-font-ttf "access plus 1 month"
694696
ExpiresByType font/opentype "access plus 1 month"

test/fixtures/.htaccess

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# ------------------------------------------------------------------------------
1111

1212
<IfModule mod_headers.c>
13-
<FilesMatch "\.(eot|otf|tt[cf]|woff)$">
13+
<FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
1414
Header set Access-Control-Allow-Origin "*"
1515
</FilesMatch>
1616
</IfModule>
@@ -64,7 +64,7 @@ ErrorDocument 404 /404.html
6464
Header set X-UA-Compatible "IE=edge"
6565
# `mod_headers` cannot match based on the content-type, however, this header
6666
# should be send only for HTML documents and not for the other resources
67-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
67+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
6868
Header unset X-UA-Compatible
6969
</FilesMatch>
7070
</IfModule>
@@ -119,6 +119,7 @@ ErrorDocument 404 /404.html
119119

120120
# Web fonts
121121
AddType application/font-woff woff
122+
AddType application/font-woff2 woff2
122123
AddType application/vnd.ms-fontobject eot
123124

124125
AddType application/x-font-ttf ttc ttf
@@ -207,7 +208,7 @@ AddDefaultCharset utf-8
207208

208209
<IfModule mod_headers.c>
209210
Header set X-Frame-Options "DENY"
210-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
211+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
211212
Header unset X-Frame-Options
212213
</FilesMatch>
213214
</IfModule>
@@ -218,7 +219,7 @@ AddDefaultCharset utf-8
218219

219220
<IfModule mod_headers.c>
220221
Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
221-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
222+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
222223
Header unset Content-Security-Policy
223224
</FilesMatch>
224225
</IfModule>
@@ -279,7 +280,7 @@ AddDefaultCharset utf-8
279280

280281
<IfModule mod_headers.c>
281282
Header set X-XSS-Protection "1; mode=block"
282-
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
283+
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff2?|xml|xpi)$">
283284
Header unset X-XSS-Protection
284285
</FilesMatch>
285286
</IfModule>
@@ -416,6 +417,7 @@ FileETag None
416417

417418
# Web fonts
418419
ExpiresByType application/font-woff "access plus 1 month"
420+
ExpiresByType application/font-woff2 "access plus 1 month"
419421
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
420422
ExpiresByType application/x-font-ttf "access plus 1 month"
421423
ExpiresByType font/opentype "access plus 1 month"

test/fixtures/test.woff2

6.02 KB
Binary file not shown.

test/tests.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ exports = module.exports = {
2727
'<!doctype html>\n' +
2828
'<html lang="en">\n' +
2929
'<head>\n' +
30-
' <meta charset="utf-8">\n' +
31-
' <title>404</title>\n' +
30+
' <meta charset="utf-8">\n'+
31+
' <title>404</title>\n' +
3232
'</head>\n' +
3333
'<body>\n' +
34-
' 404\n' +
34+
' 404\n' +
3535
'</body>\n' +
3636
'</html>\n',
3737
responseHeaders: null,
@@ -53,11 +53,11 @@ exports = module.exports = {
5353
'<!doctype html>\n' +
5454
'<html lang="en">\n' +
5555
'<head>\n' +
56-
' <meta charset="utf-8">\n' +
57-
' <title>404</title>\n' +
56+
' <meta charset="utf-8">\n' +
57+
' <title>404</title>\n' +
5858
'</head>\n' +
5959
'<body>\n' +
60-
' 404\n' +
60+
' 404\n' +
6161
'</body>\n' +
6262
'</html>\n',
6363
responseHeaders: null,
@@ -106,21 +106,21 @@ exports = module.exports = {
106106
requestHeaders: null,
107107
responseBody:
108108
'{\n' +
109-
' "name": "test",\n' +
110-
' "icons": [{\n' +
111-
' "src": "icon/lowres",\n' +
112-
' "sizes": "64x64",\n' +
113-
' "type": "image/webp"\n' +
114-
' }, {\n' +
115-
' "src": "icon/hd_small",\n' +
116-
' "sizes": "64x64"\n' +
117-
' }, {\n' +
118-
' "src": "icon/hd_hi",\n' +
119-
' "sizes": "128x128"\n' +
120-
' }],\n' +
121-
' "start_url": "/start.html",\n' +
122-
' "display": "fullscreen",\n' +
123-
' "orientation": "landscape"\n' +
109+
' "name": "test",\n' +
110+
' "icons": [{\n' +
111+
' "src": "icon/lowres",\n' +
112+
' "sizes": "64x64",\n' +
113+
' "type": "image/webp"\n' +
114+
' }, {\n' +
115+
' "src": "icon/hd_small",\n' +
116+
' "sizes": "64x64"\n' +
117+
' }, {\n' +
118+
' "src": "icon/hd_hi",\n' +
119+
' "sizes": "128x128"\n' +
120+
' }],\n' +
121+
' "start_url": "/start.html",\n' +
122+
' "display": "fullscreen",\n' +
123+
' "orientation": "landscape"\n' +
124124
'}\n',
125125
responseHeaders: null,
126126
},
@@ -146,11 +146,11 @@ exports = module.exports = {
146146
'<!doctype html>\n' +
147147
'<html lang="en">\n' +
148148
'<head>\n' +
149-
' <meta charset="utf-8">\n' +
150-
' <title>test</title>\n' +
149+
' <meta charset="utf-8">\n' +
150+
' <title>test</title>\n' +
151151
'</head>\n' +
152152
'<body>\n' +
153-
' test\n' +
153+
' test\n' +
154154
'</body>\n' +
155155
'</html>\n',
156156
responseHeaders: null
@@ -317,9 +317,9 @@ exports = module.exports = {
317317
requestHeaders: null,
318318
responseBody:
319319
'#test {\n' +
320-
' background: green;\n' +
321-
' border: 1px solid green;\n' +
322-
' color: green;\n' +
320+
' background: green;\n' +
321+
' border: 1px solid green;\n' +
322+
' color: green;\n' +
323323
'}\n',
324324
responseHeaders: null
325325
},
@@ -391,14 +391,14 @@ exports = module.exports = {
391391
requestHeaders: null,
392392
responseBody:
393393
'#test {\n' +
394-
' background: green;\n' +
395-
' border: 1px solid green;\n' +
396-
' color: green;\n' +
394+
' background: green;\n' +
395+
' border: 1px solid green;\n' +
396+
' color: green;\n' +
397397
'}\n\n' +
398398
'#test {\n' +
399-
' background: hotpink;\n' +
400-
' border: 1px solid hotpink;\n' +
401-
' color: hotpink;\n' +
399+
' background: hotpink;\n' +
400+
' border: 1px solid hotpink;\n' +
401+
' color: hotpink;\n' +
402402
'}\n\n',
403403
responseHeaders: null
404404
},

0 commit comments

Comments
 (0)