Permalink
Browse files

Merge pull request #468 from cweider/minify-simplify

Minify Simplification
  • Loading branch information...
2 parents bf42359 + cfe0954 commit 611cfbd6fa57455aef37fecb10dacde1b4ba5840 @Pita Pita committed Feb 27, 2012
Showing with 408 additions and 260 deletions.
  1. +22 −16 node/server.js
  2. +195 −237 node/utils/Minify.js
  3. +5 −0 node/utils/Settings.js
  4. +175 −0 node/utils/caching_middleware.js
  5. +2 −0 package.json
  6. +4 −0 settings.json.template
  7. +3 −5 static/js/ace.js
  8. +1 −1 static/pad.html
  9. +1 −1 static/timeslider.html
View
@@ -31,6 +31,8 @@ var async = require('async');
var express = require('express');
var path = require('path');
var minify = require('./utils/Minify');
+var CachingMiddleware = require('./utils/caching_middleware');
+var Yajsml = require('yajsml');
var formidable = require('formidable');
var apiHandler;
var exportHandler;
@@ -61,8 +63,7 @@ console.log("Report bugs at https://github.com/Pita/etherpad-lite/issues")
var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";
-//cache 6 hours
-exports.maxAge = 1000*60*60*6;
+exports.maxAge = settings.maxAge;
//set loglevel
log4js.setGlobalLogLevel(settings.loglevel);
@@ -141,21 +142,26 @@ async.waterfall([
gracefulShutdown();
});
- //serve static files
- app.get('/static/js/require-kernel.js', function (req, res, next) {
- res.header("Content-Type","application/javascript; charset: utf-8");
- res.write(minify.requireDefinition());
- res.end();
- });
- app.get('/static/*', function(req, res)
- {
- var filePath = path.normalize(__dirname + "/.." +
- req.url.replace(/\.\./g, '').split("?")[0]);
- res.sendfile(filePath, { maxAge: exports.maxAge });
+ // Cache both minified and static.
+ var assetCache = new CachingMiddleware;
+ app.all('/(minified|static)/*', assetCache.handle);
+
+ // Minify will serve static files compressed (minify enabled). It also has
+ // file-specific hacks for ace/require-kernel/etc.
+ app.all('/static/:filename(*)', minify.minify);
+
+ // Setup middleware that will package JavaScript files served by minify for
+ // CommonJS loader on the client-side.
+ var jsServer = new (Yajsml.Server)({
+ rootPath: 'minified/'
+ , rootURI: 'http://' + settings.ip + ":" + settings.port + '/static/js/'
});
-
- //serve minified files
- app.get('/minified/:filename', minify.minifyJS);
+ var StaticAssociator = Yajsml.associators.StaticAssociator;
+ var associations =
+ Yajsml.associators.associationsForSimpleMapping(minify.tar);
+ var associator = new StaticAssociator(associations);
+ jsServer.setAssociator(associator);
+ app.use(jsServer);
//checks for padAccess
function hasPadAccess(req, res, callback)
Oops, something went wrong.

0 comments on commit 611cfbd

Please sign in to comment.