GithubHelp home page GithubHelp logo

atgwwx / dynosrc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dynosrc/dynosrc

0.0 2.0 0.0 267 KB

Update static resources by sending diff patch files to the browser.

Home Page: http://dinosrc.it

License: MIT License

dynosrc's Introduction

Stories in Ready
NPM

DynoSRC is a general solution for efficiently delivering JS resources to clients, using diff-based updates as assets change over time.

Benefits

Minimize HTTP Requests

DynoSRC loads JavaScript files inline in your HTML response, then stores them in localStorage. You can even inline the calls to the DynoSRC client lib in your HTML response, eliminating all HTTP requests for JavaScript on your site.

Differential Updates

Normally, if a JS asset on your site changes, your users will have to download the entire file again even though just a fraction of it changed. DynoSRC sends down differentials updates so changes to large files don't require full downloads.

Getting Started

Install DynoSrc

npm install dynosrc

Configure Middleware

dynSrc.globals({
  //folder containing your JS / CSS files
  assetsDir: __dirname + '/assets'
});

//install express style middleware
app.use(dynoSrc.middleware());

dynSrc.assets({
  //point directly to files on github
  'ryanstevens/ModelFlow': {
    filename: 'package.json',
    source: 'git',
    //this can also be a tag
    head: '8050f1'
  },
  'jquery': {
    head: '1.9.1',
    //this lives on disk
    source: 'asset'
  }
});

Get Patches, Send to Client

app.get('/', function (req, res) {
  dynSrc.getPatches(req, {
    patches: ['jquery', 'backbone']
  }, function(err, patches) {
    res.render('index.html', {
      title: 'Super Cool Project',
      patches: patches
    });
  });
});
This will produce corresponding "patch" deltas in your HTML
//inserted from dynSrc.getPatches
dynoSrc.apply('my-cool-module', '0.1.2', '...diff...');

How does it work?

  • git diff
    • We are relying on forking out to a child_process.
    • This means the process you are running node with must have access to git.
    • The reason we are not using js-git for this was because that feature was not implemented yet.
  • DEV mode FTW
    • dynoSrc eats its own dog food in while developing. We really felt this was an important feature so this isn't just a build tool for "production". This way any bugs that come from using this strategy will appear earlier in the dev cycle, rather than in production. Here is a simple run down of what the middleware will do on every page load.
      • Look at the resources in your cookie
      • Look at every local resource in your repo that needs to be served
      • Determine if there were changes (due to direct file change via a human, or maybe grunt rewrote them)
      • Write the changed file to a scratch area with an epoc timestamp
      • Compute a diff from the last page load
      • Send ONLY the diff

TODOs

  • DEV mode WILL eat your entire HD. Someone needs to write a thing to clean up all the things :)
  • Move sever oriented unit tests out of NodeKnockout repo and into public dynoSrc repo.
  • Remove hard dependancy on shelling out to git.
  • Much of this feels like it could be complimented with a Grunt task.
  • Write client unit tests against dynoSrc.js ;)
  • Bit mask resources in cookie to not store entire resource name

dynosrc's People

Contributors

diurnalist avatar voltagex avatar waffle-with-pears avatar

Watchers

James Cloos avatar  avatar

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.