Skip to content

Commit f0f126b

Browse files
author
Mikko Tiihonen
committed
Use new configurable negotiator api for encoding sorting
1 parent 85ad87c commit f0f126b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ Compression tips:
132132
gzip encoders. Brotli compresses generally 15-20% better than gzip.
133133
* Use zopfli for gzip compression for and extra 5% benefit for all browsers.
134134

135+
Performance of serving static files is lower due to extra stats – worst case
136+
20% with 1 byte files to loopback client. Compared to on-the-fly compression
137+
the precompression is still a large win.
138+
139+
##### encodingNegotiatorOptions
140+
141+
Allows configuring the [encoding negotation options](https://github.com/jshttp/negotiator#sort-options).
142+
135143
##### root
136144

137145
Serve files relative to `path`.

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ function SendStream (req, path, options) {
163163
? opts.precompressionFormats
164164
: this._precompressionFormats
165165

166+
this._encodingNegotiatorOptions = opts.encodingNegotiatorOptions !== undefined
167+
? opts.encodingNegotiatorOptions
168+
: { sortPreference: 'clientThenServer'}
169+
166170
this._index = opts.index !== undefined
167171
? normalizeList(opts.index, 'index option')
168172
: ['index.html']
@@ -345,7 +349,7 @@ SendStream.prototype.isConditionalGET = function isConditionalGET () {
345349

346350
SendStream.prototype.getAcceptEncodingExtensions = function() {
347351
var self = this
348-
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings)
352+
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings, this._encodingNegotiatorOptions)
349353
var accepted = []
350354
for (var e = 0; e < negotiatedEncodings.length; e++) {
351355
var encoding = negotiatedEncodings[e]

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"http-errors": "~1.5.0",
2525
"mime": "1.3.4",
2626
"ms": "0.7.1",
27-
"negotiator": "jshttp/negotiator#d9907aec0585476d9a0c4271e464f7c6e4633049",
27+
"negotiator": "jshttp/negotiator#6038bf698c522c1883a1113c834e53256b35584f",
2828
"on-finished": "~2.3.0",
2929
"range-parser": "~1.2.0",
3030
"statuses": "~1.3.0",

0 commit comments

Comments
 (0)