KoaJS middleware for combining static files at serverside to reduce the number of http requests.
$ npm install koa-combo
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,...
.
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.
For security concern, you cannot use ..
in the file path. For example, http://assets.domain.com/?combo=myasset/../images
is not allowed.
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.
$ npm test
MIT