express-static-gzip
Advanced tools
Comparing version
17
index.js
@@ -37,7 +37,13 @@ var mime = require("mime"); | ||
//check if the requested file is available in at least one of the supported encodings | ||
//test if any compression is available | ||
var matchedFile = files[req.url]; | ||
var compression = matchedFile && findAvailableCompressionForFile(matchedFile.compressions, acceptEncoding); | ||
if (compression) { | ||
convertToCompressedRequest(req, res, compression); | ||
if (matchedFile) { | ||
//as long as there is any compression available for this file, add the Vary Header (used for caching proxies) | ||
res.setHeader("Vary", "Accept-Encoding"); | ||
//use the first matching compression to serve a compresed file | ||
var compression = findAvailableCompressionForFile(matchedFile.compressions, acceptEncoding); | ||
if (compression) { | ||
convertToCompressedRequest(req, res, compression); | ||
} | ||
} | ||
@@ -81,3 +87,2 @@ | ||
res.setHeader("Content-Encoding", compression.encodingName); | ||
res.setHeader("Vary", "Accept-Encoding"); | ||
res.setHeader("Content-Type", type + (charset ? "; charset=" + charset : "")); | ||
@@ -177,3 +182,3 @@ } | ||
* @param {string} fileExtension | ||
* @returns {name:string, fileExtension:string,files:[Object]} | ||
* @returns {encodingName:string, fileExtension:string,files:[Object]} | ||
*/ | ||
@@ -180,0 +185,0 @@ function Compression(encodingName, fileExtension) { |
{ | ||
"name": "express-static-gzip", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "simple wrapper on top of express.static, that allows serving pre-gziped files", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"express", | ||
"static", | ||
"gzip" | ||
"gzip", | ||
"brotli" | ||
], | ||
@@ -14,0 +12,0 @@ "author": "Tobias Koenig <tobiaskoenig1@gmail.com>", |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
11843
1.17%176
2.33%2
-33.33%