Skip to content

ljwrer/serve-webp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serve-webp

Create a new middleware function to serve images from within a given root directory. The images to serve will be determined by combining req.url with the provided root directory. When browser support webp,this module will convert the local images(jpg,gif,png) to webp and save into specify cache directory and response as webp,otherwise it will call next() to move on to the next middleware

Installation

npm install serve-webp

Usage

const serveWebp = require('serve-webp');
const app = require('express')();
app.get('/*',serveWebp({
    root:path.resolve(process.cwd()),
    cache:path.resolve(process.cwd(),'webp')
}));

config

root

images root directory

use path.join(root, req.url) as file path

cache

webp cache directory

About

a express middleware convert the local images(jpg,gif,png) to webp and save into specify cache directory and response as webp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published