1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-22 12:41:21 +00:00

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 * Add file extensions ourselves to push state
* Proper markdown highlighting * Proper markdown highlighting
* Better about page text * Better about page text
* auto-compress assets
* add feedback for errors to UI - esp. too long * add feedback for errors to UI - esp. too long
# shared version only # shared version only

View file

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

View file

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

View file

@ -37,6 +37,26 @@ if (!config.storage.type) {
var Store = require('./lib/' + config.storage.type + '_document_store'); var Store = require('./lib/' + config.storage.type + '_document_store');
var preferredStore = new Store(config.storage); 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 // Send the static documents into the preferred store, skipping expirations
for (var name in config.documents) { for (var name in config.documents) {
var path = config.documents[name]; 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="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="http://yandex.st/highlightjs/6.1/highlight.min.js"></script>
<script type="text/javascript" src="application.js"></script> <script type="text/javascript" src="application.min.js"></script>
<script type="text/javascript" src="ZeroClipboard.js"></script> <script type="text/javascript" src="ZeroClipboard.min.js"></script>
<meta name="robots" content="noindex,nofollow"/> <meta name="robots" content="noindex,nofollow"/>