From f73996044aaace25c0d992a932159d7f61771b78 Mon Sep 17 00:00:00 2001 From: Steve Krenek Date: Tue, 10 Jun 2014 17:04:20 -0500 Subject: [PATCH 1/2] Added caching defaults to socket.io. Made jquery and bootstrap pull from CDN by default instead of locally. --- lib/config.json | 9 ++++-- lib/resource-packager.js | 65 ++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/lib/config.json b/lib/config.json index 107c866..66795e1 100755 --- a/lib/config.json +++ b/lib/config.json @@ -54,7 +54,10 @@ "port": 8081, "host": "localhost", "log level": 1, - "log level docs": "0 = error, 1 = warn, 2 = info, 3 = debug" + "log level docs": "0 = error, 1 = warn, 2 = info, 3 = debug", + "browser client minification": true, + "browser client etag": true, + "browser client gzip": true }, "auth": { @@ -220,7 +223,7 @@ { "name": "bootstrap", "jsFiles": [ - "/feather-client/lib/bootstrap/js/bootstrap.min.js", + "//netdna.bootstrapcdn.com/twitter-bootstrap/2.0.4/js/bootstrap.min.js", "/feather-client/ui-bootstrap.js" ], "cssFiles": [ @@ -231,7 +234,7 @@ { "name": "bootstrap3", "jsFiles": [ - "/feather-client/lib/bootstrap3/js/bootstrap.min.js", + "//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js", "/feather-client/ui-bootstrap3.js" ], "cssFiles": [ diff --git a/lib/resource-packager.js b/lib/resource-packager.js index 5933622..3091829 100755 --- a/lib/resource-packager.js +++ b/lib/resource-packager.js @@ -38,8 +38,8 @@ var getPackagePublisher = function(options, callback) { var newCache = false, hrefPrefix = typeof options.hrefPrefix === "undefined" ? "/" : options.hrefPrefix, resourceOptions = options.appOptions.resources, - pkg = _.detect(resourceOptions.packages, function(pkg) { - return pkg.name === options.cacheName || pkg.publishType === options.publishType; + pkg = _.detect(resourceOptions.packages, function(pkg) { + return pkg.name === options.cacheName || pkg.publishType === options.publishType; }), publisherOptions = null; @@ -65,10 +65,10 @@ var getPackagePublisher = function(options, callback) { }); publisher.publishers.add(availableResourcePublishers.findById(publisherOptions.id)); resourcePublishersInUse.add(publisher); - } + } callback(null, _.extend({ - publisher: publisher, + publisher: publisher, packageOptions: pkgOptions, newCache: newCache, }, options)); @@ -88,18 +88,18 @@ var getPackagePublisher = function(options, callback) { * } * @name resourcePackager.packageResources * @param {Object} options see example in description above. - * @function + * @function */ exports.packageResources = function(options, callback) { if (!options.files || !options.files.length) { callback("Cannot package resources; the files array is either empty or not present."); } else { simpleCache.getItem("feather-logger", function(err, logger) { - + getPackagePublisher(options, function(err, getPubResults) { - var publisher = getPubResults.publisher, - packageOptions = getPubResults.packageOptions, + var publisher = getPubResults.publisher, + packageOptions = getPubResults.packageOptions, //publisherOptions = _.extend(getPubResults.publisher.publisherOptions, pkgOptions), newCache = getPubResults.newCache, consolidate = packageOptions.consolidate, @@ -129,7 +129,7 @@ exports.packageResources = function(options, callback) { $j.tmpl(options.template, { href: component.url }).appendTo($j('resources')); - }); + }); } } } @@ -140,7 +140,7 @@ exports.packageResources = function(options, callback) { var sem = new Semaphore(function() { publisher.publish({ publisherOptions: publisher.publisherOptions, - packageOptions: packageOptions + packageOptions: packageOptions }, finalizePublish); }); sem.semaphore = options.files.length; @@ -151,7 +151,7 @@ exports.packageResources = function(options, callback) { var filePath = path.join(file.prefix+file.path), minifyAllowed = (!file.minifyAllowed || file.minifyAllowed === true); // if it's true or missing, minify is allowed. - fs.readFile(filePath, "utf8", function(err, content) { + fs.readFile(filePath, "utf8", function(err, content) { if (err) { if(!filePath.match(/\.css$/)) { //not an error state if we're missing a css file - don't log logger.error({message:"unable to open " + filePath + ": " + err, immediately: true, category:"feather.respack"}); @@ -244,15 +244,16 @@ exports.packageFrameworkResources = function(options, callback) { var prefix = options.appOptions.featherRoot, featherFiles = items['feather-files'], restProxyInfo = items['feather-restProxyInfo']; - + var cssFiles = []; - + // js ----------------------------------------------------------------- var jsFiles = [ {path: "/feather-client/lib/underscore-min.js", prefix: prefix}, options.appOptions["socket.io"].enabled ? {path: "/socket.io/socket.io.js", prefix: prefix, virtual: true} : null, {path: "/feather-client/lib/json2.js", prefix: prefix, minifyAllowed: false}, - {path: "/feather-client/lib/jquery-1.7.min.js", prefix: prefix}, + //{path: "/feather-client/lib/jquery-1.7.min.js", prefix: prefix}, + {path: "https://code.jquery.com/jquery-1.7.2.min.js", prefix: prefix, virtual: true}, // {path: "/feather-client/lib/jquery-1.9.migrate.min.js", prefix: prefix}, {path: "/feather-client/lib/jquery.tmpl.js", prefix: prefix}, {path: "/feather-client/lib/jquery.cookie.js", prefix: prefix}, @@ -277,20 +278,20 @@ exports.packageFrameworkResources = function(options, callback) { prefix: restProxyInfo.prefix }); } - + // Only add the auth scripts if this app has auth enabled. if (options.appOptions.auth.enabled) { //jsFiles.push({path: "feather-client/sha512.js", prefix: prefix}); jsFiles.push({path: "/feather-client/auth-client.js", prefix: prefix}); } - + // Add datalinking if enabled if (options.appOptions.data.datalinking.enabled) { jsFiles.push({path: "/feather-client/lib/jquery.datalink.js", prefix: prefix}); } - + // Add files for the ui provider if enabled - if (options.appOptions.ui.enabled) { + if (options.appOptions.ui.enabled) { var uiJSPrefix = prefix, uiCSSPrefix = prefix, provider = options.appOptions.ui.provider, @@ -303,11 +304,17 @@ exports.packageFrameworkResources = function(options, callback) { } //get the js files + var nonLocalRegex = /^(\/\/|https?:\/\/)/; var appFiles = _.keys(featherFiles.appFiles); if (provider.jsRoot === "/") uiJSPrefix = options.appOptions.publicRoot; _.each(provider.jsFiles, function(file) { var _path = file, - _prefix = uiJSPrefix; + _prefix = uiJSPrefix, + virtual = false; + + if (nonLocalRegex.test(_path)) { + virtual = true; + } //detect automatic app overrides (via dropping in new files in the /public/_ui folder) var fileName = path.basename(file); @@ -319,8 +326,8 @@ exports.packageFrameworkResources = function(options, callback) { _prefix = options.appOptions.publicRoot; _path = '/' + path.relative(options.appOptions.publicRoot, overrideFile); } - - jsFiles.push({path: _path, prefix: _prefix}); + + jsFiles.push({path: _path, prefix: _prefix, virtual: virtual}); }); //get the css files @@ -339,7 +346,7 @@ exports.packageFrameworkResources = function(options, callback) { _prefix = options.appOptions.publicRoot; _path = '/' + path.relative(options.appOptions.publicRoot, overrideFile); } - + cssFiles.push({path: _path, prefix: _prefix}); }); } @@ -353,12 +360,12 @@ exports.packageFrameworkResources = function(options, callback) { }); var frameworkPackaged = new Semaphore(callback); - + frameworkPackaged.increment(); exports.packageResources(jsOptions, function(err) { frameworkPackaged.execute(err); }); - + if (cssFiles.length) { var cssOptions = _.extend(_.clone(options), { @@ -412,7 +419,7 @@ exports.packageWidgetResources = function(options, callback) { * url(i.jpg); */ exports.resolveCssUrls = function (filePath, content) { - + // TODO: Make sure http urls work. var urlRegex = /url\((["']?)([^\/|^"\/|^'\/].+)(["']?)\)/g var dir = path.dirname(filePath); @@ -436,7 +443,7 @@ function packageWidgetJs(options, callback) { contentType: "text/javascript", files: [] }); - + options.widgetClassRegistry.each(function(widgetClass) { var widgetJsFiles = []; if (widgetClass.classDef && !widgetClass.classDef.prototype.serverOnly) { @@ -447,8 +454,8 @@ function packageWidgetJs(options, callback) { // Include any other js files in the widget's folder. widgetJsFiles = _.filter(fs.readdirSync(path.join(options.appOptions.publicRoot, widgetClass.widgetRoot)), function(filename) { - return path.extname(filename) === ".js" - && filename !== path.basename(widgetClass.clientHrefPath) + return path.extname(filename) === ".js" + && filename !== path.basename(widgetClass.clientHrefPath) && filename !== (widgetClass.widgetName + '.server.js'); }); @@ -464,7 +471,7 @@ function packageWidgetJs(options, callback) { } function packageWidgetCss(options, callback) { - + var packageInfo = _.extend(_.clone(options), { template: '', cacheName: path.relative(options.appOptions.publicRoot, path.resolve(options.appOptions.publicRoot, options.request.page)) + '.css', From b1971de2267363ce0d83b0589e3d5cd2b7a0b16a Mon Sep 17 00:00:00 2001 From: Steve Krenek Date: Wed, 11 Jun 2014 16:03:25 -0500 Subject: [PATCH 2/2] Gzip is possible again. Now using connect's built-in compress middleware instead of connect-gzip. --- lib/middleware.js | 12 ++++-------- package.json | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 7686e5f..a7450a4 100755 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -1,7 +1,6 @@ var Connect = require("connect"), router = require("./router"), - cache = require("./simple-cache"); - gzip = require('connect-gzip'), + cache = require("./simple-cache"), feather = require('./feather'), Semaphore = require('./semaphore'), _ = require("underscore")._, @@ -73,11 +72,7 @@ exports.getMiddleware = function(options, cb) { router.getRouter(options, function(err, _router) { if (err) cb(err); else { - if(options.resources.publish.gzip){ - var staticHandler = gzip.staticGzip(options.publicRoot); - } else { - var staticHandler = Connect.static(options.publicRoot); - } + var staticHandler = Connect.static(options.publicRoot); var bodyParserMiddleware = bodyParser(); var multerOptions = _.extend({}, appOptions.safeGet('connect.bodyParser.multipart'), appOptions.fileUploadOptions); @@ -278,7 +273,8 @@ exports.getMiddleware = function(options, cb) { ]; if(options.resources.publish.gzip){ - middleware.unshift(gzip.gzip()); + logger.debug('enabling gzip'); + middleware.unshift(Connect.compress({threshold: 2048})); } function completeMiddleware() { diff --git a/package.json b/package.json index 62e0d6d..61b2868 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "cli": "~0.4.5", "colorize": "~0.1.0", "connect": "~2.12.0", - "connect-gzip": "git+http://github.com/tikonen/connect-gzip.git#44bccfe4b3", "connect-redis": "1.4.6", "cradle": "git+http://github.com/ryedin/cradle.git#4246311c3b87", "daemon": "~1.1.0",