开发者社区> 镜像站> NPM> polyfill-middleware
polyfill-middleware
http middleware to serve polyfill.js based on browser
Last updated 7 years ago by shtylman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install polyfill-middleware 
SYNC missed versions from official npm registry.

polyfill-middleware Build Status

http and express middleware serves selective polyfills for javascript based on the requesting user-agent.

which polyfills?

See the polyfill project for details about which polyfills and browsers are supported.

install

npm install polyfill-middleware

use with express

You can use the polyfill middleware with express by specifying which path to serve the dynamically generated js from.

The below examples assumes the following script tag <script src="/assets/polyfill.js"></script>

var polyfill = require('polyfill-middleware');

app.use('/assets/polyfill.js', polyfill());

// alternatively you can limit to just `get` requests
app.get('/assets/polyfill.js', polyfill());

use with node.js http server

The middleware function takes 3 arguments (request, response, done). done should be a function and will be called if the polyfill middleware encountered an error. If there was no error, polyfill middleware will respond to the request.

var middleware = polyfill();

http.createServer(function(req, res) {
    // .. some logic to determine if the request should be handled by polyfill
    middleware(req, res, function(err) {
    });
});

examples

More examples are available in the examples directory.

Current Tags

  • 0.0.0                                ...           latest (7 years ago)

1 Versions

  • 0.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (3)
Dependents (0)
None