diff --git a/README.md b/README.md index f581d2e..ca36733 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,14 @@ Compression tips: gzip encoders. Brotli compresses generally 15-20% better than gzip. * Use zopfli for gzip compression for and extra 5% benefit for all browsers. +Performance of serving static files is lower due to extra stats – worst case +20% with 1 byte files to loopback client. Compared to on-the-fly compression +the precompression is still a large win. + +##### encodingNegotiatorOptions + +Allows configuring the [encoding negotation options](https://github.com/jshttp/negotiator#sort-options). + ##### root Serve files relative to `path`. diff --git a/index.js b/index.js index 5e5cfa2..1560257 100644 --- a/index.js +++ b/index.js @@ -170,6 +170,10 @@ function SendStream (req, path, options) { ? opts.precompressionFormats : this._precompressionFormats + this._encodingNegotiatorOptions = opts.encodingNegotiatorOptions !== undefined + ? opts.encodingNegotiatorOptions + : { sortPreference: 'clientThenServer' } + this._index = opts.index !== undefined ? normalizeList(opts.index, 'index option') : ['index.html'] @@ -386,7 +390,7 @@ SendStream.prototype.isPreconditionFailure = function isPreconditionFailure () { SendStream.prototype.getAcceptEncodingExtensions = function () { var self = this - var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings) + var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings, this._encodingNegotiatorOptions) var accepted = [] for (var e = 0; e < negotiatedEncodings.length; e++) { var encoding = negotiatedEncodings[e] diff --git a/package.json b/package.json index 6d82ef2..22e2848 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "http-errors": "~1.6.1", "mime": "1.3.4", "ms": "0.7.2", - "negotiator": "jshttp/negotiator#d9907aec0585476d9a0c4271e464f7c6e4633049", + "negotiator": "jshttp/negotiator#6038bf698c522c1883a1113c834e53256b35584f", "on-finished": "~2.3.0", "range-parser": "~1.2.0", "statuses": "~1.3.1",