Code Monkey home page Code Monkey logo

join-io's Introduction

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

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

join-io's People

Contributors

coderaiser avatar kuldipem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

join-io's Issues

[Feature Request] Load a list of JavaScript files from a JSON file

In a lot of my past PHP projects, I had a script I wrote that would "include a folder". It did this by first loading a file called jspackage.json in that folder, which listed the paths - ordered, relative to the JSON file - of JavaScript files to be loaded. The the script would combine all this into one clump of JavaScript and send it to the client.

It would be really cool, I think, to bring that same functionality to Express, and this seems like the right module to do so. This is something I might have time to implement in the next couple of weeks.

Stylus issue with Express

Using join-io in an Express project with livecompile of *.styl files everytime server starts build a compressed css without new edits: for view edits in my *.styl files (built into css files) I need to view in a new browser tab the css compiled file (eg: command+t on Chrome, view localhost:3000/css/style.css) and refresh window.

My piece of code where are server settings:

app
  .use(
    stylus.middleware({ 
      src: path.join(__dirname, 'public'), 
      compile: function (str, path) { 
        return stylus(str)
                .set('filename', path)
                .set('compress', true)
                .use(nib());
      } 
    })
  )
  .use(favicon(__dirname + '/public/img/favicon.png'))
  .use(logger('dev'))
  .use(bodyParser.urlencoded({ extended: true }))
  .use(bodyParser.json())
  .use(methodOverride())
  .use(cookieParser('xxx'))
  .use(
    session({
      secret: 'xxx',
      saveUninitialized: true,
      resave: true
    })
  )
  .use(express.static(path.join(__dirname, 'public')))
  .use( joinio({ dir: path.join(__dirname, 'public'), prefix: '/join', minify: true }) )
  .use(errorHandler());

and my jade template css linking

link(rel='stylesheet', href='/join:/font/font_icons8.css:/css/style.css:/css/mobile.css')

Is there a sort of cache or anything related to it?

Thank you!

May accidentally expose internal code

With the default config. I can request any .js file from my server through the \join prefix, ie: http://localhost:3001/join:app.js

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

Although I can protect my backend with different dir path, but should this be noticed beforehand?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.