koa-combo

1.0.1 • Public • Published

koa-combo

KoaJS middleware for combining static files at serverside to reduce the number of http requests.

Installation

$ npm install koa-combo

Usage

Enabling combo is as simple as following

var koa = require('koa'),
  app = koa(),
  combo = require('koa-combo');
 
app.use(combo(['example-parts/']));

To access your combined static files, use the query string pattern combo=path-of-file-1,path-of-file-2,path-of-file-3,....

API

combo(allowedPrefix)

Enable combo.

Parameters:

  • allowedPrefix (string|array[string])

You should always specify array allowedPrefix. All files do not begin with any string in allowedPrefix will not be served.

Security

For security concern, you cannot use .. in the file path. For example, http://assets.domain.com/?combo=myasset/../images is not allowed.

Example

Run example.js in harmony mode. Ensure your node supports ES6 harmony mode.

$ node --harmony example.js

Then visit http://localhost:3000/?combo=example-parts/part1.js,example-parts/part2.js, you will get the combined version of example-parts/part1.js and example-parts/part2.js. Files are concatenated by the given order in query string.

Testing

$ npm test

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i koa-combo

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • tjwudi