Skip to content

Commit

Permalink
Speed up dependency loader and update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Jul 22, 2011
1 parent 3aaa6d7 commit b70ef31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions autoloader.js
Expand Up @@ -21,7 +21,7 @@ module.exports = function setup(mount, folder, uglify) {
return function handle(req, res, next) { return function handle(req, res, next) {
if (!req.uri) { req.uri = Url.parse(req.url); } if (!req.uri) { req.uri = Url.parse(req.url); }
if (req.uri.pathname !== mount) return next(); if (req.uri.pathname !== mount) return next();
var names = req.uri.query.split(","); var names = req.uri.query.split(",").reverse();


var has = {}; var has = {};
var scripts = []; var scripts = [];
Expand All @@ -38,11 +38,11 @@ module.exports = function setup(mount, folder, uglify) {
if (matches) { if (matches) {
matches = Array.prototype.slice.call(matches).map(function (dep) { matches = Array.prototype.slice.call(matches).map(function (dep) {
return dep.match(findName)[1]; return dep.match(findName)[1];
}); }).reverse();


function getDep(err) { function getDep(err) {
if (err) return next(err); if (err) return next(err);
var dep = matches.shift(); var dep = matches.pop();
if (!dep) return doneDeps(); if (!dep) return doneDeps();
loadScript(dep, getDep); loadScript(dep, getDep);
} }
Expand All @@ -64,7 +64,7 @@ module.exports = function setup(mount, folder, uglify) {


function getName(err) { function getName(err) {
if (err) return next(err); if (err) return next(err);
var name = names.shift(); var name = names.pop();
if (!name) return done(); if (!name) return done();
loadScript(name, getName); loadScript(name, getName);
} }
Expand Down
7 changes: 2 additions & 5 deletions autoloader/bootstrap.js
@@ -1,8 +1,5 @@
// This is a super simple module system for use in the browser. You first // Super simple require system to go along with the server-side help in the
// define your module using the "define" function and then later require it // autoloader middleware for "creationix".
// using "require" This does not support circular dependencies or require search
// paths. It's a simple module repository for writing clean code.

(function () { (function () {


// Store our repository in private variables in this closure. // Store our repository in private variables in this closure.
Expand Down

0 comments on commit b70ef31

Please sign in to comment.