Skip to content

Commit 6a7574a

Browse files
author
Mikko Tiihonen
committed
Remove brotli references from documentation and index.js
1 parent b95c987 commit 6a7574a

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,18 @@ usage when serving files.
9595

9696
The `precompressed` option enables or disables serving of precompressed
9797
content variants. The option defaults to `false`, if set to `true` checks
98-
for existence of brotli and gzip compressed files with `.br` and `.gz`
99-
extensions, preferring brotli if the file exists and supported by the
100-
browser.
98+
for existence of gzip compressed files with `.gz` extensions.
10199

102100
Example scenario:
103101

104-
The file `site.css` has both `site.css.gz` and `site.css.br`
105-
precompressed versions available in the same directory.
106-
When a request comes with an `Accept-Encoding` header with value `gzip, br`
107-
requesting `site.css` the contents of `site.css.br` is sent instead and
102+
The file `site.css` has both `site.css.gz` and `site.css.bz2`
103+
precompressed versions available in the same directory. The server is configured
104+
to serve both `.bz2` and `.gz` files in that prefence order.
105+
When a request comes with an `Accept-Encoding` header with value `gzip, bz2`
106+
requesting `site.css` the contents of `site.css.bz2` is sent instead and
108107
a header `Content-Encoding` with value `br` is added to the response.
109108
In addition a `Vary: Accept-Encoding` header is added to response allowing
110-
proxies to work correctly.
109+
caching proxies to work correctly.
111110

112111
Custom configuration:
113112

@@ -119,7 +118,7 @@ them explicitly in an array in the preferred priority order. For example:
119118
Compression tips:
120119
* Precompress at least all static `js`, `css` and `svg` files.
121120
* Precompress using both brotli (supported by Firefox and Chrome) and
122-
gzip encoders.
121+
gzip encoders. Brotli compresses generally 15-20% better than gzip.
123122
* Use zopfli for gzip compression for and extra 5% benefit for all browsers.
124123

125124
##### root

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function SendStream(req, path, options) {
120120
this._precompressionFormats = opts.precompressed
121121
}
122122
} else if (opts.precompressed) {
123-
this._precompressionFormats = [{encoding: 'br', extension:'.br'}, {encoding:'gzip', extension:'.gz'}]
123+
this._precompressionFormats = [{encoding:'gzip', extension:'.gz'}]
124124
}
125125

126126
this._precompressionFormats = opts.precompressionFormats !== undefined

test/send.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,9 +1106,10 @@ describe('send(file, options)', function(){
11061106
.expect('Vary', 'Accept-Encoding', done)
11071107
})
11081108

1109-
it('should send brotli when present with equal weight in accept-encoding', function(done){
1109+
it('should prefer server encoding order (br,gzip) when present with equal weight in accept-encoding', function(done){
11101110
var app = http.createServer(function(req, res){
1111-
send(req, req.url, {precompressed: true, root: fixtures})
1111+
send(req, req.url, {precompressed: [{encoding: 'br', extension: '.br'},
1112+
{encoding: 'gzip', extension: '.gz'}], root: fixtures})
11121113
.pipe(res);
11131114
});
11141115

@@ -1121,35 +1122,35 @@ describe('send(file, options)', function(){
11211122
.expect('Content-Length', '15', done)
11221123
})
11231124

1124-
it('should send gzip when preferred in accept-encoding', function(done){
1125+
it('should prefer server encoding order (gzip,br) when present with equal weight in accept-encoding', function(done){
11251126
var app = http.createServer(function(req, res){
1126-
send(req, req.url, {precompressed: true, root: fixtures})
1127+
send(req, req.url, {precompressed: [{encoding: 'gzip', extension: '.gz'},
1128+
{encoding: 'br', extension: '.br'}], root: fixtures})
11271129
.pipe(res);
11281130
});
11291131

11301132
request(app)
11311133
.get('/name.html')
1132-
.set('Accept-Encoding', ' gzip , deflate')
1134+
.set('Accept-Encoding', 'br, deflate, gzip')
11331135
.expect('Vary', 'Accept-Encoding')
11341136
.expect('Content-Encoding', 'gzip')
11351137
.expect('Content-Type', 'text/html; charset=UTF-8')
11361138
.expect('Content-Length', '31', done)
11371139
})
11381140

1139-
it('should honor explicit precompression format configuration', function(done){
1141+
it('should send gzip when preferred in accept-encoding', function(done){
11401142
var app = http.createServer(function(req, res){
1141-
send(req, req.url, {precompressed: [{encoding: 'fake', extension: ''},
1142-
{encoding: 'gzip', extension: '.gz'}], root: fixtures})
1143+
send(req, req.url, {precompressed: true, root: fixtures})
11431144
.pipe(res);
11441145
});
11451146

11461147
request(app)
11471148
.get('/name.html')
1148-
.set('Accept-Encoding', 'gzip, fake')
1149+
.set('Accept-Encoding', ' gzip , deflate')
11491150
.expect('Vary', 'Accept-Encoding')
1150-
.expect('Content-Encoding', 'fake')
1151+
.expect('Content-Encoding', 'gzip')
11511152
.expect('Content-Type', 'text/html; charset=UTF-8')
1152-
.expect('Content-Length', '11', done)
1153+
.expect('Content-Length', '31', done)
11531154
})
11541155

11551156
it('should not send gzip when no-gzip encoding is used', function(done){
@@ -1220,7 +1221,8 @@ describe('send(file, options)', function(){
12201221

12211222
it('should return server preferred format for accept-encoding *', function(done){
12221223
var app = http.createServer(function(req, res){
1223-
send(req, req.url, {precompressed: true, root: fixtures})
1224+
send(req, req.url, {precompressed: [{encoding: 'br', extension: '.br'},
1225+
{encoding: 'gzip', extension: '.gz'}], root: fixtures})
12241226
.pipe(res);
12251227
});
12261228

0 commit comments

Comments
 (0)