Skip to content

Commit

Permalink
Remove brotli references from documentation and index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikko Tiihonen committed Jun 2, 2016
1 parent b95c987 commit 6a7574a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,18 @@ usage when serving files.

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

Example scenario:

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

Custom configuration:

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

##### root
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function SendStream(req, path, options) {
this._precompressionFormats = opts.precompressed
}
} else if (opts.precompressed) {
this._precompressionFormats = [{encoding: 'br', extension:'.br'}, {encoding:'gzip', extension:'.gz'}]
this._precompressionFormats = [{encoding:'gzip', extension:'.gz'}]
}

this._precompressionFormats = opts.precompressionFormats !== undefined
Expand Down
26 changes: 14 additions & 12 deletions test/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,10 @@ describe('send(file, options)', function(){
.expect('Vary', 'Accept-Encoding', done)
})

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

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

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

request(app)
.get('/name.html')
.set('Accept-Encoding', ' gzip , deflate')
.set('Accept-Encoding', 'br, deflate, gzip')
.expect('Vary', 'Accept-Encoding')
.expect('Content-Encoding', 'gzip')
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect('Content-Length', '31', done)
})

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

request(app)
.get('/name.html')
.set('Accept-Encoding', 'gzip, fake')
.set('Accept-Encoding', ' gzip , deflate')
.expect('Vary', 'Accept-Encoding')
.expect('Content-Encoding', 'fake')
.expect('Content-Encoding', 'gzip')
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect('Content-Length', '11', done)
.expect('Content-Length', '31', done)
})

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

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

Expand Down

0 comments on commit 6a7574a

Please sign in to comment.