Skip to content
Browse files

Warmup support + some code cleanup in zazl.js

  • Loading branch information...
1 parent ebf36c5 commit c5772abe5a451f79de3b438713c390fd2b00e3d0 @rbackhouse rbackhouse committed
View
368 org.dojotoolkit.optimizer.amd/loader/amd/zazl.js
@@ -15,7 +15,7 @@ var define;
var cjsVarPrefixRegExp = /^~#/;
var pluginRegExp = /.+!/;
- Iterator = function(array) {
+ var Iterator = function(array) {
this.array = array;
this.current = 0;
};
@@ -40,19 +40,55 @@ var define;
var injectQueue = [];
var injectInProcess = false;
var requireInProcess = false;
-
+ var cfg;
+ var pageLoaded = false;
+ var modulesLoaded = false;
+ var domLoaded = false;
+ var readyCallbacks = [];
+
var opts = Object.prototype.toString;
var geval = window.execScript || eval;
- function isFunction(it) { return opts.call(it) === "[object Function]"; };
- function isArray(it) { return opts.call(it) === "[object Array]"; };
- function isString(it) { return (typeof it == "string" || it instanceof String); };
+ function isFunction(it) { return opts.call(it) === "[object Function]"; }
+ function isArray(it) { return opts.call(it) === "[object Array]"; }
+ function isString(it) { return (typeof it === "string" || it instanceof String); }
function _getCurrentId() {
- return moduleStack.length > 0 ? moduleStack[moduleStack.length-1] : "";
+ return moduleStack.length > 0 ? moduleStack[moduleStack.length-1] : "";
}
+ function countSegments(path) {
+ var count = 0;
+ for (var i = 0; i < path.length; i++) {
+ if (path.charAt(i) === '/') {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ function findMapping(path, depId) {
+ var mapping;
+ var segmentCount = -1;
+ for (var id in cfg.map) {
+ if (depId.indexOf(id) === 0) {
+ var foundSegmentCount = countSegments(id);
+ if (foundSegmentCount > segmentCount) {
+ var mapEntry = cfg.map[id];
+ if (mapEntry[path] !== undefined) {
+ mapping = mapEntry[path];
+ segmentCount = foundSegmentCount;
+ }
+ }
+ }
+ }
+ if (mapping === undefined && cfg.map["*"] !== undefined && cfg.map["*"][path] !== undefined) {
+ mapping = cfg.map["*"][path];
+ }
+ return mapping;
+ }
+
function _normalize(path) {
var segments = path.split('/');
var skip = 0;
@@ -70,7 +106,7 @@ var define;
}
}
return segments.join('/');
- };
+ }
function _expand(path) {
var isRelative = path.search(/^\./) === -1 ? false : true;
@@ -83,9 +119,10 @@ var define;
}
path = _normalize(path);
}
+ var pkgName;
for (pkgName in pkgs) {
if (path === pkgName) {
- return pkgs[pkgName].name + '/' + pkgs[pkgName].main;
+ return pkgs[pkgName].name + '/' + pkgs[pkgName].main;
}
}
@@ -93,72 +130,117 @@ var define;
for (var i = segments.length; i >= 0; i--) {
var parent = segments.slice(0, i).join("/");
var mapping = findMapping(parent, _getCurrentId());
- if (mapping) {
- segments.splice(0, i, mapping);
- return segments.join("/");
- }
+ if (mapping) {
+ segments.splice(0, i, mapping);
+ return segments.join("/");
+ }
}
return path;
- };
+ }
- function countSegments(path) {
- var count = 0;
- for (var i = 0; i < path.length; i++) {
- if (path.charAt(i) === '/') {
- count++;
- }
- }
- return count;
- };
-
- function findMapping(path, depId) {
- var mapping;
- var segmentCount = -1;
- for (var id in cfg.map) {
- if (depId.indexOf(id) === 0) {
- var foundSegmentCount = countSegments(id);
- if (foundSegmentCount > segmentCount) {
- var mapEntry = cfg.map[id];
- if (mapEntry[path] !== undefined) {
- mapping = mapEntry[path];
- segmentCount = foundSegmentCount;
- }
- }
- }
- }
- if (mapping === undefined && cfg.map["*"] !== undefined && cfg.map["*"][path] !== undefined) {
- mapping = cfg.map["*"][path];
- }
- return mapping;
- };
-
function _idToUrl(path) {
var segments = path.split("/");
for (var i = segments.length; i >= 0; i--) {
var pkg;
var parent = segments.slice(0, i).join("/");
if (paths[parent]) {
- segments.splice(0, i, paths[parent]);
+ segments.splice(0, i, paths[parent]);
break;
}else if ((pkg = pkgs[parent])) {
- var pkgPath;
+ var pkgPath;
if (path === pkg.name) {
pkgPath = pkg.location + '/' + pkg.main;
} else {
pkgPath = pkg.location;
}
- segments.splice(0, i, pkgPath);
- break;
+ segments.splice(0, i, pkgPath);
+ break;
}
}
path = segments.join("/");
if (path.charAt(0) !== '/') {
- path = cfg.baseUrl + path;
+ path = cfg.baseUrl + path;
}
path = _normalize(path);
return path;
- };
+ }
+
+ function _loadModuleDependencies(id, cb) {
+ var m = modules[id];
+ var idx = 0;
+ var iterate = function(itr) {
+ if (itr.hasMore()) {
+ var dependency = itr.next();
+ var argIdx = idx++;
+ var depname;
+ var add;
+ if (dependency.match(pluginRegExp)) {
+ add = true;
+ if (dependency.match(cjsVarPrefixRegExp)) {
+ dependency = dependency.substring(2);
+ add = false;
+ }
+ var pluginName = dependency.substring(0, dependency.indexOf('!'));
+ pluginName = _expand(pluginName);
+ var pluginModuleName = dependency.substring(dependency.indexOf('!')+1);
+ if (add) {
+ m.dependencies[argIdx] = pluginName + "!"+pluginModuleName;
+ m.args[argIdx] = undefined;
+ depname = pluginName + "!"+pluginModuleName;
+ } else {
+ depname = "~#"+pluginName + "!"+pluginModuleName;
+ }
+ m.deploaded[depname] = false;
+ _loadPlugin(pluginName, pluginModuleName, function(pluginInstance) {
+ if (add) {
+ m.args[argIdx] = pluginInstance;
+ }
+ m.deploaded[depname] = true;
+ });
+ iterate(itr);
+ } else if (dependency === 'require') {
+ m.args[argIdx] = _createRequire(_getCurrentId());
+ m.deploaded['require'] = true;
+ iterate(itr);
+ } else if (dependency === 'module') {
+ m.args[argIdx] = m;
+ m.deploaded['module'] = true;
+ iterate(itr);
+ } else if (dependency === 'exports') {
+ m.args[argIdx] = m.exports;
+ m.deploaded['exports'] = true;
+ iterate(itr);
+ } else {
+ add = true;
+ if (dependency.match(cjsVarPrefixRegExp)) {
+ dependency = dependency.substring(2);
+ add = false;
+ }
+ var expandedId = _expand(dependency);
+ if (add) {
+ m.dependencies[argIdx] = expandedId;
+ m.args[argIdx] = modules[expandedId] === undefined ? undefined : modules[expandedId].exports;
+ depname = expandedId;
+ } else {
+ depname = "~#"+expandedId;
+ }
+ m.deploaded[depname] = false;
+ _loadModule(dependency, function(module){
+ if (add) {
+ m.args[argIdx] = module;
+ }
+ m.deploaded[depname] = true;
+ });
+ iterate(itr);
+ }
+ } else {
+ m.cjsreq = _createRequire(_getCurrentId());
+ cb();
+ }
+ };
+ iterate(new Iterator(m.dependencies));
+ }
function _loadModule(id, cb, scriptText) {
var expandedId = _expand(id);
@@ -176,25 +258,25 @@ var define;
cblist[expandedId].push({cb:cb, mid:dependentId});
return;
}
- function _load() {
- moduleStack.push(expandedId);
+ function _load() {
+ moduleStack.push(expandedId);
if (scriptText) {
geval(scriptText);
}
- _loadModuleDependencies(expandedId, function() {
- moduleStack.pop();
+ _loadModuleDependencies(expandedId, function() {
+ moduleStack.pop();
cblist[expandedId].push({cb:cb, mid:dependentId});
});
- };
+ }
- function inInjectQueue(id) {
- for (var i = 0; i < injectQueue.length; i++) {
- if (injectQueue[i].id === id) {
- return true;
- }
- }
- return false;
- };
+ function inInjectQueue(id) {
+ for (var i = 0; i < injectQueue.length; i++) {
+ if (injectQueue[i].id === id) {
+ return true;
+ }
+ }
+ return false;
+ }
if (modules[expandedId] === undefined && scriptText === undefined) {
if (inInjectQueue(expandedId)) {
@@ -206,11 +288,12 @@ var define;
} else {
_load();
}
- };
+ }
function _inject(moduleIds, cb) {
var notLoaded = [];
- for (var i = 0; i < moduleIds.length; i++) {
+ var i;
+ for (i = 0; i < moduleIds.length; i++) {
var id = moduleIds[i];
if (id.match(pluginRegExp)) {
id = id.substring(0, id.indexOf('!'));
@@ -229,9 +312,10 @@ var define;
locale = dojoConfig.locale;
}
function clone(obj) {
- if (null == obj || "object" != typeof obj) return obj;
+ if (null === obj || "object" !== typeof obj) { return obj; }
+ var copy;
if (obj instanceof Array) {
- var copy = [];
+ copy = [];
var len = obj.length;
for (var i = 0; i < len; ++i) {
copy[i] = clone(obj[i]);
@@ -239,7 +323,7 @@ var define;
return copy;
}
if (obj instanceof Object) {
- var copy = {};
+ copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) {
if (isFunction(obj[attr])) {
@@ -255,12 +339,12 @@ var define;
}
var configString = JSON.stringify(clone(cfg));
var url = cfg.injectUrl+"?modules=";
- for (var i = 0; i < notLoaded.length; i++) {
+ for (i = 0; i < notLoaded.length; i++) {
url += notLoaded[i];
url += i < (notLoaded.length - 1) ? "," : "";
}
url += "&writeBootstrap=false&locale="+locale+"&config="+encodeURIComponent(configString)+"&exclude=";
- for (var i = 0; i < analysisKeys.length; i++) {
+ for (i = 0; i < analysisKeys.length; i++) {
url += analysisKeys[i];
url += i < (analysisKeys.length - 1) ? "," : "";
}
@@ -283,82 +367,7 @@ var define;
}
};
document.getElementsByTagName("head")[0].appendChild(script);
- };
-
- function _loadModuleDependencies(id, cb) {
- var m = modules[id];
- var idx = 0;
- var iterate = function(itr) {
- if (itr.hasMore()) {
- var dependency = itr.next();
- var argIdx = idx++;
- var depname;
- if (dependency.match(pluginRegExp)) {
- var add = true;
- if (dependency.match(cjsVarPrefixRegExp)) {
- dependency = dependency.substring(2);
- add = false;
- }
- var pluginName = dependency.substring(0, dependency.indexOf('!'));
- pluginName = _expand(pluginName);
- var pluginModuleName = dependency.substring(dependency.indexOf('!')+1);
- if (add) {
- m.dependencies[argIdx] = pluginName + "!"+pluginModuleName;
- m.args[argIdx] = undefined;
- depname = pluginName + "!"+pluginModuleName;
- } else {
- depname = "~#"+pluginName + "!"+pluginModuleName;
- }
- m.deploaded[depname] = false;
- _loadPlugin(pluginName, pluginModuleName, function(pluginInstance) {
- if (add) {
- m.args[argIdx] = pluginInstance;
- }
- m.deploaded[depname] = true;
- });
- iterate(itr);
- } else if (dependency === 'require') {
- m.args[argIdx] = _createRequire(_getCurrentId());
- m.deploaded['require'] = true;
- iterate(itr);
- } else if (dependency === 'module') {
- m.args[argIdx] = m;
- m.deploaded['module'] = true;
- iterate(itr);
- } else if (dependency === 'exports') {
- m.args[argIdx] = m.exports;
- m.deploaded['exports'] = true;
- iterate(itr);
- } else {
- var add = true;
- if (dependency.match(cjsVarPrefixRegExp)) {
- dependency = dependency.substring(2);
- add = false;
- }
- var expandedId = _expand(dependency);
- if (add) {
- m.dependencies[argIdx] = expandedId;
- m.args[argIdx] = modules[expandedId] === undefined ? undefined : modules[expandedId].exports;
- depname = expandedId;
- } else {
- depname = "~#"+expandedId;
- }
- m.deploaded[depname] = false;
- _loadModule(dependency, function(module){
- if (add) {
- m.args[argIdx] = module;
- }
- m.deploaded[depname] = true;
- });
- iterate(itr);
- }
- } else {
- m.cjsreq = _createRequire(_getCurrentId());
- cb();
- }
- };
- iterate(new Iterator(m.dependencies));
- };
+ }
function _loadPlugin(pluginName, pluginModuleName, cb) {
_loadModule(pluginName, function(plugin){
@@ -377,8 +386,8 @@ var define;
if (pluginInstance === undefined) {
pluginInstance = null;
}
- modules[pluginName+"!"+pluginModuleName] = {};
- modules[pluginName+"!"+pluginModuleName].exports = pluginInstance;
+ modules[pluginName+"!"+pluginModuleName] = {};
+ modules[pluginName+"!"+pluginModuleName].exports = pluginInstance;
cb(pluginInstance);
};
load.fromText = function(name, text) {
@@ -387,7 +396,7 @@ var define;
};
plugin.load(pluginModuleName, req, load, cfg);
});
- };
+ }
function _createRequire(id) {
var req = function(dependencies, callback) {
@@ -430,27 +439,27 @@ var define;
// Dojo specific require properties and functions
req.cache = cache;
req.toAbsMid = function(id) {
- return _expand(id);
+ return _expand(id);
};
req.isXdUrl = function(url) {
- return false;
+ return false;
};
req.idle = function() {
- return pageLoaded;
+ return pageLoaded;
};
req.on = function(type, callback) {
- if (type === "idle") {
- if (pageLoaded) {
- callback();
- } else {
- readyCallbacks.push(callback);
- }
- } else {
- console.log("Unsupported 'on' type ["+type+"]");
- }
+ if (type === "idle") {
+ if (pageLoaded) {
+ callback();
+ } else {
+ readyCallbacks.push(callback);
+ }
+ } else {
+ console.log("Unsupported 'on' type ["+type+"]");
+ }
};
return req;
- };
+ }
define = function (id, dependencies, factory) {
if (!isString(id)) {
@@ -488,7 +497,7 @@ var define;
jQuery: true
};
- _require = function (dependencies, callback) {
+ var _require = function (dependencies, callback) {
if (isString(dependencies)) {
var id = dependencies;
id = _expand(id);
@@ -543,8 +552,6 @@ var define;
modules["require"].loaded = true;
modules["require"].dependencies = [];
- var cfg;
-
function processConfig(config) {
if (!cfg) {
var i;
@@ -584,7 +591,7 @@ var define;
};
zazl = function(config, dependencies, callback) {
- if (!isArray(config) && typeof config == "object") {
+ if (!isArray(config) && typeof config === "object") {
processConfig(config);
} else {
callback = dependencies;
@@ -606,7 +613,7 @@ var define;
});
processCache();
queueProcessor();
- };
+ }
function _load() {
requireInProcess = true;
@@ -618,7 +625,7 @@ var define;
} else {
_callRequire();
}
- };
+ }
if (requireInProcess) {
var poller = function() {
@@ -654,11 +661,6 @@ var define;
analysisKeys.push(key);
};
- var pageLoaded = false;
- var modulesLoaded = false;
- var domLoaded = false;
- var readyCallbacks = [];
-
document.addEventListener("DOMContentLoaded", function() {
domLoaded = true;
if (modulesLoaded) {
@@ -686,7 +688,7 @@ var define;
}
}
return complete;
- };
+ }
function processInjectQueue() {
if (!injectInProcess && injectQueue.length > 0) {
@@ -699,14 +701,6 @@ var define;
}
}
- function queueProcessor() {
- var poller = function() {
- if (processQueues()) { return; }
- setTimeout(poller, 0);
- };
- poller();
- };
-
function processQueues() {
var allLoaded = true, mid, m, ret;
@@ -781,5 +775,13 @@ var define;
if (requireInProcess) { requireInProcess = false; }
}
return allLoaded;
- };
+ }
+
+ function queueProcessor() {
+ var poller = function() {
+ if (processQueues()) { return; }
+ setTimeout(poller, 0);
+ };
+ poller();
+ }
}());
View
154 org.dojotoolkit.optimizer.amd/loader/amd/zazlwarmup.js
@@ -0,0 +1,154 @@
+/*
+ Copyright (c) 2004-2013, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+var zazlWarmup;
+
+(function () {
+ var opts = Object.prototype.toString;
+
+ function isFunction(it) { return opts.call(it) === "[object Function]"; };
+ function isArray(it) { return opts.call(it) === "[object Array]"; };
+ function isString(it) { return (typeof it == "string" || it instanceof String); };
+
+ function clone(obj) {
+ if (null == obj || "object" != typeof obj) return obj;
+ if (obj instanceof Array) {
+ var copy = [];
+ var len = obj.length;
+ for (var i = 0; i < len; ++i) {
+ copy[i] = clone(obj[i]);
+ }
+ return copy;
+ }
+ if (obj instanceof Object) {
+ var copy = {};
+ for (var attr in obj) {
+ if (obj.hasOwnProperty(attr)) {
+ if (isFunction(obj[attr])) {
+ copy[attr] = "function";
+ } else {
+ copy[attr] = clone(obj[attr]);
+ }
+ }
+ }
+ return copy;
+ }
+ throw new Error("Unable to clone");
+ };
+
+ function normalize(path) {
+ var segments = path.split('/');
+ var skip = 0;
+
+ for (var i = (segments.length-1); i >= 0; i--) {
+ var segment = segments[i];
+ if (segment === '.') {
+ segments.splice(i, 1);
+ } else if (segment === '..') {
+ segments.splice(i, 1);
+ skip++;
+ } else if (skip) {
+ segments.splice(i, 1);
+ skip--;
+ }
+ }
+ return segments.join('/');
+ };
+
+ function createConfig() {
+ var i;
+ var cfg = clone(zazlConfig);
+ if (cfg.packages) {
+ for (i = 0; i < cfg.packages.length; i++) {
+ var pkg = cfg.packages[i];
+ if (!pkg.location) {
+ pkg.location = pkg.name;
+ }
+ if (!pkg.main) {
+ pkg.main = "main";
+ } else if (pkg.main.match(/.js$/g)) {
+ pkg.main = pkg.main.substring(0, pkg.main.lastIndexOf(".js"));
+ }
+ cfg.packages[i] = pkg;
+ }
+ }
+ cfg.baseUrl = cfg.baseUrl || "./";
+
+ if (cfg.baseUrl.charAt(0) !== '/' && !cfg.baseUrl.match(/^[\w\+\.\-]+:/)) {
+ cfg.baseUrl = normalize(window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/'+ cfg.baseUrl);
+ }
+
+ cfg.injectUrl = cfg.injectUrl || "_javascript";
+ cfg.scanCJSRequires = cfg.scanCJSRequires || false;
+ cfg.debug = cfg.debug || false;
+ cfg.config = cfg.config || {};
+ cfg.map = cfg.map || {};
+ return cfg;
+ };
+
+ function createScriptTag(url, cb) {
+ var script = document.createElement('script');
+ script.type = "text/javascript";
+ script.src = url;
+ script.charset = "utf-8";
+ script.onloadDone = false;
+ script.onload = function() {
+ if (!script.onloadDone) {
+ script.onloadDone = true;
+ cb();
+ }
+ };
+ script.onreadystatechange = function(){
+ if (("loaded" === script.readyState || "complete" === script.readyState) && !script.onloadDone) {
+ script.onload();
+ }
+ };
+ document.getElementsByTagName("head")[0].appendChild(script);
+ };
+
+ function createZazlUrl(url, modules) {
+ var locale = "en-us";
+ if (window.dojoConfig && window.dojoConfig.locale) {
+ locale = dojoConfig.locale;
+ }
+ var configString = JSON.stringify(createConfig());
+ var zazlUrl = url+"?modules=";
+ for (var i = 0; i < modules.length; i++) {
+ zazlUrl += modules[i];
+ zazlUrl += i < (modules.length - 1) ? "," : "";
+ }
+ zazlUrl += "&writeBootstrap=false&locale="+locale+"&config="+encodeURIComponent(configString)+"&exclude=";
+ return zazlUrl;
+ };
+
+ zazlWarmup = function(zazlscripturl, altscripturl, modules, cb) {
+ if (!zazlConfig) {
+ throw new Error("A zazlConfig object must be defined");
+ }
+ var xhr = new XMLHttpRequest();
+ var url = zazlConfig.injectUrl || "_javascript";
+ var zazlUrl = createZazlUrl(url, modules);
+ xhr.open("HEAD", zazlUrl, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ if (xhr.status == 200 || xhr.status == 304) {
+ createScriptTag(zazlscripturl, function() {
+ console.log("loaded zazl script tag");
+ cb();
+ });
+ } else if (xhr.status == 404) {
+ createScriptTag(altscripturl, function() {
+ console.log("loaded alternative script tag");
+ cb();
+ });
+ } else {
+ throw new Error("Zazl Servlet Head request failed : "+xhr.status);
+ }
+ }
+ };
+ xhr.send(null);
+ }
+}());
View
2 org.dojotoolkit.optimizer.servlet/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Dojo Toolkit Optimizer Servlet
Bundle-SymbolicName: org.dojotoolkit.optimizer.servlet
-Bundle-Version: 0.5.0
+Bundle-Version: 0.5.3
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: javax.servlet,
javax.servlet.http,
View
BIN ...kit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSHandler$OptimizerRunnable.class
Binary file not shown.
View
BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSHandler.class
Binary file not shown.
View
BIN org.dojotoolkit.optimizer.servlet/org/dojotoolkit/optimizer/servlet/JSServlet.class
Binary file not shown.
View
58 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/JSHandler.java
@@ -36,6 +36,7 @@
import org.dojotoolkit.json.JSONParser;
import org.dojotoolkit.optimizer.CachingJSOptimizer;
import org.dojotoolkit.optimizer.JSAnalysisData;
+import org.dojotoolkit.optimizer.JSAnalysisDataImpl;
import org.dojotoolkit.optimizer.JSOptimizer;
import org.dojotoolkit.optimizer.JSOptimizerFactory;
import org.dojotoolkit.optimizer.Util;
@@ -137,8 +138,8 @@ public boolean handle(HttpServletRequest request, HttpServletResponse response)
}
String configString = request.getParameter("config");
@SuppressWarnings("unchecked")
- Map<String, Object> config = (Map<String, Object>)JSONParser.parse(new StringReader(configString));
- analysisData = jsOptimizer.getAnalysisData(modules, exclude, config);
+ Map<String, Object> pageConfig = (Map<String, Object>)JSONParser.parse(new StringReader(configString));
+ analysisData = jsOptimizer.getAnalysisData(modules, exclude, pageConfig);
} else if (key != null) {
analysisData = jsOptimizer.getAnalysisData(key);
}
@@ -200,6 +201,42 @@ public boolean handle(HttpServletRequest request, HttpServletResponse response)
public JSOptimizer getJSOptimizer() {
return jsOptimizer;
}
+
+ public void handleHeadRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String[] modules = null;
+ String modulesParam = request.getParameter("modules");
+ JSAnalysisData[] exclude = EMPTY_ARRAY;
+ if (modulesParam != null) {
+ modules = getAsList(modulesParam);
+ String configString = request.getParameter("config");
+ @SuppressWarnings("unchecked")
+ Map<String, Object> pageConfig = (Map<String, Object>)JSONParser.parse(new StringReader(configString));
+ String key = JSAnalysisDataImpl.getKey(modules, exclude, pageConfig);
+ JSAnalysisData analysisData = jsOptimizer.getAnalysisData(key);
+ if (analysisData != null) {
+ String checksum = analysisData.getChecksum();
+ String ifNoneMatch = request.getHeader("If-None-Match");
+
+ if (ifNoneMatch != null && ifNoneMatch.equals(checksum)) {
+ response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ return;
+ }
+
+ response.setHeader("ETag", checksum);
+
+ String version = request.getParameter("version");
+ if (version != null && version.equals(checksum)) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.YEAR, 1);
+ response.setDateHeader("Expires", calendar.getTimeInMillis());
+ }
+ response.setStatus(HttpServletResponse.SC_OK);
+ return;
+ }
+ new Thread(new OptimizerRunnable(jsOptimizer, modules, pageConfig)).start();
+ }
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
protected boolean handleSourceMapRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sourcemapKey = request.getParameter("sourcemap");
@@ -258,6 +295,7 @@ protected boolean handleSourceMapRequest(HttpServletRequest request, HttpServlet
private JSOptimizer optimizer = null;
private String[] modules = null;
private String modulesAsString = "";
+ private Map<String, Object> pageConfig = null;
public OptimizerRunnable(JSOptimizer optimizer, List<String> modules) {
this.optimizer = optimizer;
@@ -269,10 +307,24 @@ public OptimizerRunnable(JSOptimizer optimizer, List<String> modules) {
}
}
+ public OptimizerRunnable(JSOptimizer optimizer, String[] modules, Map<String, Object> pageConfig) {
+ this.optimizer = optimizer;
+ this.modules = modules;
+ for (String module : modules) {
+ modulesAsString += module;
+ modulesAsString += ' ';
+ }
+ this.pageConfig = pageConfig;
+ }
+
public void run() {
try {
logger.logp(Level.INFO, getClass().getName(), "run", "Obtaining Optimization Data for ["+modulesAsString+"]");
- optimizer.getAnalysisData(modules);
+ if (config == null) {
+ optimizer.getAnalysisData(modules);
+ } else {
+ optimizer.getAnalysisData(modules, EMPTY_ARRAY, pageConfig);
+ }
logger.logp(Level.INFO, getClass().getName(), "run", "Obtained Optimization Data for ["+modulesAsString+"]");
} catch (IOException e) {
logger.logp(Level.SEVERE, getClass().getName(), "OptimizerRunnable", "IOException while attempting to obtain Optimization Data for ["+modulesAsString+"]", e);
View
6 org.dojotoolkit.optimizer.servlet/src/org/dojotoolkit/optimizer/servlet/JSServlet.java
@@ -151,6 +151,10 @@ public void init(ServletConfig config) throws ServletException {
}
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- jsHandler.handle(request, response);
+ if (request.getMethod().equals("HEAD")) {
+ jsHandler.handleHeadRequest(request, response);
+ } else {
+ jsHandler.handle(request, response);
+ }
}
}
View
2 org.dojotoolkit.optimizer/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Optimizer
Bundle-SymbolicName: org.dojotoolkit.optimizer
-Bundle-Version: 0.5.2
+Bundle-Version: 0.5.3
Import-Package: org.dojotoolkit.json,
org.dojotoolkit.server.util.resource,
org.dojotoolkit.server.util.rhino
View
BIN org.dojotoolkit.optimizer/org/dojotoolkit/optimizer/JSAnalysisDataImpl.class
Binary file not shown.
View
1 org.dojotoolkit.optimizer/src/org/dojotoolkit/optimizer/JSAnalysisDataImpl.java
@@ -12,7 +12,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
-import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.math.BigInteger;

0 comments on commit c5772ab

Please sign in to comment.
Something went wrong with that request. Please try again.