join files on a fly to reduce requests count
JavaScript
Latest commit f73bc33 Nov 28, 2016 coderaiser chore(package) v1.4.5

README.md

Join-io

Join files on a fly to reduce requests count.

Install

npm i join-io --save

How it works?

join-io it's middleware that works with streams: open files and pipe them to response one-by-one, when everything is done, stream is closing. join-io based on readPipe function of files-io.

jsDelivr works in similar way: load Multiple files with a single HTTP request.

How to use?

Join-io could be used as express middleware.

Client

<link rel="/join:/css/normilize.css:/css/style.css">
<script src="/join:/lib/client.js:/lib/util.js:/lib/jquery.js"></script>

Join.js

You could build join urls dynamically. Load /join/join.js library for this purpose.

<script src="/join/join.js"></script>
<script>
    join(['lib/client', 'lib/util.js']);
</script>

To decrease requests count you could make /join/join.js part of request:

<script src="/join:/lib/client.js:/lib/util.js:/join/join.js"></script>

Instead of /join you could use any prefix you like (don't forget to set it on the server side).

Server

var join        = require('join-io'),
    http        = require('http'),
    express     = require('express'),

    app         = express(),
    server      = http.createServer(app),

    port        = 1337,
    ip          = '0.0.0.0';

app.use(join({
    dir: __dirname,
    prefix: '/join',    /* default */
    minify: false       /* default */
}));

app.use(express.static(__dirname));

server.listen(port, ip);

License

MIT