Generates and delivers JPG-, PNG- and TIFF-images on the fly as WebP-images if the client supports that format.
Inspired by a post from Cloudinary, this middleware generates and delivers JPG-, PNG- and TIFF-images on the fly as WebP-images if the requesting client supports that format.
WebP is a new image format from Google that provides lossless and lossy compression for images on the web. For more information please read the official documentation or the article on html5rocks.com about image compression.
npm install webp-middleware
var http = require'http';var express = require'express';var webp = require'webp-middleware';var app = express;appusewebp__dirname + '/public' ;appuseexpressstatic__dirname + '/public';
It is important to insert the webp middleware before the express.static middleware.
First parameter is the path of the static folder.
Second parameter is an optional options object.
You can also have a look into the example folder for examples.
cacheDiris the directory where the webp files are saved. Default is a folder webp-cache in the executing directory (
presetdelegates to the
-presetoption at cwebp
qualitydelegates to the
-qoption at cwebp
alphaQualitydelegates to the
-alpha_qoption at cwebp
methoddelegates to the
-moption at cwebp
segmentsdelegates to the
-segmentsoption at cwebp
bytesdelegates to the
-sizeoption at cwebp
psnrdelegates to the
-psnroption at cwebp
sizedelegates to the
-soption at cwebp. Should be an object with
spatialNoiseShapingdelegates to the
-snsoption at cwebp
filterdelegates to the
-foption at cwebp
strongdelegates to the
-strongoption at cwebp. Should be a boolean value
noStrongdelegates to the
-nostrongoption at cwebp. Should be a boolean value
partitionLimitdelegates to the
-partition_limitoption at cwebp
passdelegates to the
-passoption at cwebp
cropdelegates to the
-cropoption at cwebp. Should be an object with
resizedelegates to the
-resizeoption at cwebp. Should be an object with
multiThreadingdelegates to the
-mtoption at cwebp. Should be a boolean value
lowMemorydelegates to the
-low_memoryoption at cwebp. Should be a boolean value
alphaMethoddelegates to the
-alpha_methodoption at cwebp
alphaCleanupdelegates to the
-alpha_cleanupoption at cwebp. Should be a boolean value
noAlphadelegates to the
-noalphaoption at cwebp. Should be a boolean value
losslessdelegates to the
-losslessoption at cwebp. Should be a boolean value
hintdelegates to the
-hintoption at cwebp
metadatadelegates to the
-metadataoption at cwebp
Licensed under the MIT License.