Skip to content

Instantly share code, notes, and snippets.

@justinbmeyer
Created May 10, 2012 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinbmeyer/2651141 to your computer and use it in GitHub Desktop.
Save justinbmeyer/2651141 to your computer and use it in GitHub Desktop.
require-ideal-js

There's so many things wrong with the world of script loading today. I want an easy way to:

  • install locally scripts and their dependencies
  • load these scripts from my application

I want it to:

  • work readily with almost all existing projects, source that does not use the script loader
  • handle versioning
  • have as few configs as possible
  • work ok with a JMVC style directory structure
  • avoid loading duplicate versions at all costs (a big difference with npm)

How?

Consider a grid widget that depends on jQuery UI, CanJS, and jquerypp

define('project/supergrid(1.0)',['jqueryui(>= 1.8)/positionable',
                         'jquerypp(>= 1.0)/event/resize',
                         'underscore(1.3.3)',
                         'can(>= 1.0)/control'], function(pos,resize, _, control){

})

Registry:

{
   jquery : "http://code.jquery.com/jquery-{}.js",
   can : "https://github.com/jupiterjs/canjs/zipball/v{}",
   underscore: "https://github.com/documentcloud/underscore/zipball/{1.3.3}"
}

Installing

With just project/supergrid.js defined as above run:

X install project/supergrid.js

problem whole zipped project must be downloaded to figure out dependencies. Not sure which version however.

Questions:

  1. Is it possible to register a CDN that would work with this so things don't have to be local

  2. What would the registry look like?

    jquery : "http://code.jquery.com/jquery-{}.js"

  3. How would it know the version it has w/o a config?

    It would just go to 'jquery' and use that. You would get a warning if version doesn't work.

    How do you manage needing 2 versions? - config!

  4. How would can declare it's version?

    define("can(1.0") // in can/main.js or can/can.js
    

Scenarios

Directory style

I really like:

control\
  control.js
  control_test.js
  control.html (demo page)

This is how I encourage everyone to develop, with self-contained modules for testing, experimentation, etc. This is just steal('control'). With no .js, steal just copies the last part and adds it again. I know I'm alone on this and it's now how most people organize their projects, but most people are wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment