Join files on a fly to reduce requests count
npm install join-ioJoin files on a fly to reduce requests count.
npm i join-io --save
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.
Join-io could be used as express middleware.
``html`
#### Join.js
You could build join urls dynamically. Load /join/join.js library for this purpose.
`html`
To decrease requests count you could make /join/join.js part of request:
`html`
Instead of /join you could use any prefix you like (don't forget to set it on the server side).
`js
const join = require('join-io');
const http = require('http');
const express = require('express');
const app = express();
const server = http.createServer(app);
const port = 1337;
const ip = '0.0.0.0';
app.use(join({
dir: __dirname,
prefix: '/join', / default /
}));
app.use(express.static(__dirname));
server.listen(port, ip);
``
MIT