https://github.com/coderaiser/join-io
join files on a fly to reduce requests count
https://github.com/coderaiser/join-io
cloudcmd express express-middleware javascript nodejs
Last synced: 9 months ago
JSON representation
join files on a fly to reduce requests count
- Host: GitHub
- URL: https://github.com/coderaiser/join-io
- Owner: coderaiser
- License: mit
- Created: 2014-08-14T12:20:44.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-01-25T18:34:17.000Z (almost 5 years ago)
- Last Synced: 2025-03-29T21:07:39.117Z (9 months ago)
- Topics: cloudcmd, express, express-middleware, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 50.8 KB
- Stars: 81
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
- awesome-express - join-io - 一个模块,用于实时联接文件以减少请求数目。 (中间件)
README
# 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](https://github.com/coderaiser/files-io "Files-io").
[jsDelivr](https://jsdelivr.com/ "jsDelivr") works in similar way: [load Multiple files with a single HTTP request](https://www.maxcdn.com/blog/jsdelivr-better/ "load Multiple files with a single HTTP").
## How to use?
`Join-io` could be used as express middleware.
### Client
```html
```
#### Join.js
You could build join urls dynamically. Load `/join/join.js` library for this purpose.
```html
join(['lib/client', 'lib/util.js']);
```
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).
### Server
```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);
```
## License
MIT