diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 9730f9b046..3a09141907 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -4,6 +4,7 @@ var swarmgw = require('swarmgw') var request = require('request') module.exports = { + previouslyHandled: {}, // cache import so we don't make the request at each compilation. handleGithubCall: function (root, path, cb) { return request.get( { @@ -61,6 +62,11 @@ module.exports = { }, import: function (url, loadingCb, cb) { + var self = this + var imported = this.previouslyHandled[url] + if (imported) { + return cb(null, imported.content, imported.cleanUrl, imported.type, url) + } var handlers = this.handlers() var found = false @@ -79,7 +85,11 @@ module.exports = { cb('Unable to import "' + cleanUrl + '": ' + err) return } - + self.previouslyHandled[url] = { + content: content, + cleanUrl: cleanUrl, + type: handler.type + } cb(null, content, cleanUrl, handler.type, url) }) }