Auto-compress javascript assets

This commit is contained in:
John Crepezzi 2011-11-27 15:49:17 -05:00
parent d3ba2e4b5b
commit 0875ba6252
7 changed files with 28 additions and 4 deletions

View File

@ -5,7 +5,6 @@
* Add file extensions ourselves to push state
* Proper markdown highlighting
* Better about page text
* auto-compress assets
* add feedback for errors to UI - esp. too long
# shared version only

View File

@ -9,6 +9,8 @@
"staticMaxAge": 86400,
"recompressStaticAssets": true,
"logging": [
{
"level": "verbose",

View File

@ -20,7 +20,8 @@
"dependencies": {
"winston": "*",
"hashlib": "*",
"connect": "*"
"connect": "*",
"uglify-js": "*"
},
"devDependencies": {

View File

@ -37,6 +37,26 @@ if (!config.storage.type) {
var Store = require('./lib/' + config.storage.type + '_document_store');
var preferredStore = new Store(config.storage);
// Compress the static javascript assets
if (config.recompressStaticAssets) {
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var list = fs.readdirSync('./static');
for (var i = 0; i < list.length; i++) {
var item = list[i];
var orig_code, ast;
if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) {
dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3);
orig_code = fs.readFileSync('./static/' + item, 'utf8');
ast = jsp.parse(orig_code);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
fs.writeFileSync('./static/' + dest, pro.gen_code(ast), 'utf8');
winston.info('compressed ' + item + ' into ' + dest);
}
}
}
// Send the static documents into the preferred store, skipping expirations
for (var name in config.documents) {
var path = config.documents[name];

1
static/ZeroClipboard.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
static/application.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,8 +9,8 @@
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript" src="http://yandex.st/highlightjs/6.1/highlight.min.js"></script>
<script type="text/javascript" src="application.js"></script>
<script type="text/javascript" src="ZeroClipboard.js"></script>
<script type="text/javascript" src="application.min.js"></script>
<script type="text/javascript" src="ZeroClipboard.min.js"></script>
<meta name="robots" content="noindex,nofollow"/>