Auto-compress javascript assets
This commit is contained in:
parent
d3ba2e4b5b
commit
0875ba6252
1
TODO.md
1
TODO.md
|
@ -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
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
"staticMaxAge": 86400,
|
"staticMaxAge": 86400,
|
||||||
|
|
||||||
|
"recompressStaticAssets": true,
|
||||||
|
|
||||||
"logging": [
|
"logging": [
|
||||||
{
|
{
|
||||||
"level": "verbose",
|
"level": "verbose",
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"winston": "*",
|
"winston": "*",
|
||||||
"hashlib": "*",
|
"hashlib": "*",
|
||||||
"connect": "*"
|
"connect": "*",
|
||||||
|
"uglify-js": "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
20
server.js
20
server.js
|
@ -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];
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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"/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue