From 44d70904d36f659084afccb5ea1e7045786cee42 Mon Sep 17 00:00:00 2001 From: Gabriel Lesperance Date: Sun, 11 Mar 2012 19:41:30 -0400 Subject: [PATCH] ADDED - gzip compression of static files + bumped version --- lib/client/client.js | 26 ++++++++++++++------------ lib/config.js | 6 ++++-- package.json | 3 ++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index 5cef544..533837e 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -1,15 +1,16 @@ -var async = require('async') - , fs = require('fs') - , path = require('path') - , express = require('express') +var async = require('async') + , fs = require('fs') + , path = require('path') + , express = require('express') - , jade = require('jade') + , jade = require('jade') - , child_process = require('child_process') - , events = require('events') + , child_process = require('child_process') + , events = require('events') - , EventEmitter = events.EventEmitter + , EventEmitter = events.EventEmitter + , gzip = require('connect-gzip') ; var asyncFs = require('../util/async_fs') @@ -33,6 +34,7 @@ var asyncFs = require('../util/async_fs') , JADE_RUNTIME_FILE_NAME = config.JADE_RUNTIME_FILE_NAME + , STATIC_FILES_CACHE_LIFETIME = config.STATIC_FILES_CACHE_LIFETIME ; /****************************************************************************** @@ -625,13 +627,13 @@ exports.setup = function setup_client() { * sets up a static middleware to serve the webapp `client/static` folder * as `/static` */ - app.use('/static', express.static(static_dir_path)); + app.use('/static', gzip.staticGzip(static_dir_path, { maxAge : STATIC_FILES_CACHE_LIFETIME })); /*** * sets up a static middleware to serve the rocket `rocket-js` folder * as `/rocket-js` */ - app.use('/js/rocket', express.static(path.join(__dirname, 'rocket-js'))); + app.use('/js/rocket', gzip.staticGzip(path.join(__dirname, 'rocket-js'), { maxAge : STATIC_FILES_CACHE_LIFETIME })); if (process.env['NODE_ENV'] === 'production') { @@ -644,7 +646,7 @@ exports.setup = function setup_client() { //sets up a static middleware to serve the webapp optimized tmp js folder //as `/js` - app.use('/js', express.static(client_js_tmpdir.path)); + app.use('/js', gzip.staticGzip(client_js_tmpdir.path, { maxAge : STATIC_FILES_CACHE_LIFETIME })); callback(null); } @@ -659,7 +661,7 @@ exports.setup = function setup_client() { //sets up a static middleware to serve the webapp optimized tmp css folder //as `/css` - app.use('/css', express.static(client_css_tmpdir.path)); + app.use('/css', gzip.staticGzip(client_css_tmpdir.path, { maxAge : STATIC_FILES_CACHE_LIFETIME })); callback(null); diff --git a/lib/config.js b/lib/config.js index 512c4ec..01ea72b 100644 --- a/lib/config.js +++ b/lib/config.js @@ -56,7 +56,9 @@ module.exports = new function() { this.LOCALES_NAME_REGEXP = new RegExp(this.MODULE_NAME_REGEXP); - this.DEVELOPMENT_LISTEN_PORT = 3000 - this.PRODUCTION_LISTEN_PORT = 80 + this.DEVELOPMENT_LISTEN_PORT = 3000; + this.PRODUCTION_LISTEN_PORT = 80; + + this.STATIC_FILES_CACHE_LIFETIME = 365 * 86400000; //one-year }; \ No newline at end of file diff --git a/package.json b/package.json index 0ede626..7778a54 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rocket" , "description": "The rapid development framework for node.js" , "keywords": ["mvc", "model view controller", "comet","rapid development", "Rocket", "framework"] -, "version": "0.1.19" +, "version": "0.2.0" , "homepage": "http://wavo.me" , "repository": { "type" : "git" @@ -28,6 +28,7 @@ , "jade-i18n" : "= 0.0.2" , "now" : ">= 0.7.4" , "colors" : "0.6.x" + , "connect-gzip" : "0.1.5" } , "devDependencies": { "jessie" : ">= 0.3.7"