Skip to content

Commit 9fced00

Browse files
Mikko TiihonenMikko Tiihonen
Mikko Tiihonen
authored and
Mikko Tiihonen
committed
Use new configurable negotiator api for encoding sorting
1 parent 6eb007f commit 9fced00

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
@@ -139,6 +139,14 @@ Compression tips:
139139
gzip encoders. Brotli compresses generally 15-20% better than gzip.
140140
* Use zopfli for gzip compression for and extra 5% benefit for all browsers.
141141

142+
Performance of serving static files is lower due to extra stats – worst case
143+
20% with 1 byte files to loopback client. Compared to on-the-fly compression
144+
the precompression is still a large win.
145+
146+
##### encodingNegotiatorOptions
147+
148+
Allows configuring the [encoding negotation options](https://github.com/jshttp/negotiator#sort-options).
149+
142150
##### root
143151

144152
Serve files relative to `path`.

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ function SendStream (req, path, options) {
170170
? opts.precompressionFormats
171171
: this._precompressionFormats
172172

173+
this._encodingNegotiatorOptions = opts.encodingNegotiatorOptions !== undefined
174+
? opts.encodingNegotiatorOptions
175+
: { sortPreference: 'clientThenServer'}
176+
173177
this._index = opts.index !== undefined
174178
? normalizeList(opts.index, 'index option')
175179
: ['index.html']
@@ -386,7 +390,7 @@ SendStream.prototype.isPreconditionFailure = function isPreconditionFailure () {
386390

387391
SendStream.prototype.getAcceptEncodingExtensions = function() {
388392
var self = this
389-
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings)
393+
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings, this._encodingNegotiatorOptions)
390394
var accepted = []
391395
for (var e = 0; e < negotiatedEncodings.length; e++) {
392396
var encoding = negotiatedEncodings[e]

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"http-errors": "~1.6.1",
2727
"mime": "1.3.4",
2828
"ms": "0.7.2",
29-
"negotiator": "jshttp/negotiator#d9907aec0585476d9a0c4271e464f7c6e4633049",
29+
"negotiator": "jshttp/negotiator#6038bf698c522c1883a1113c834e53256b35584f",
3030
"on-finished": "~2.3.0",
3131
"range-parser": "~1.2.0",
3232
"statuses": "~1.3.1",

0 commit comments

Comments
 (0)