Gzipped assets

This commit is contained in:
khlieng 2015-02-05 01:37:34 +01:00
parent 92c316e9ea
commit 5110029f3a
5 changed files with 33 additions and 16 deletions

View File

@ -4,6 +4,7 @@ var minifyHTML = require('gulp-minify-html');
var minifyCSS = require('gulp-minify-css');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var gzip = require('gulp-gzip');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
@ -69,10 +70,23 @@ function js(watch) {
return rebundle();
}
gulp.task('gzip', ['html', 'css', 'js'], function() {
gulp.src('./dist/*.{html,css,js}')
.pipe(gzip())
.pipe(gulp.dest('./dist'));
});
gulp.task('gzip:watch', function() {
gulp.src('./dist/*.{html,css,js}')
.pipe(gzip())
.pipe(gulp.dest('./dist'));
});
gulp.task('watch', ['default'], function() {
gulp.watch('./dist/*.{html,css,js}', ['gzip:watch'])
gulp.watch('./src/*.html', ['html']);
gulp.watch('./src/*.css', ['css']);
return js(true);
});
gulp.task('default', ['html', 'css', 'js']);
gulp.task('default', ['html', 'css', 'js', 'gzip']);

View File

@ -16,12 +16,14 @@
"watchify": "~2.2.1",
"browserify": "~8.0.3",
"gulp-autoprefixer": "~2.0.0",
"reactify": "~0.17.1"
"reactify": "~0.17.1",
"gulp-gzip": "0.0.8"
},
"dependencies": {
"lodash": "3.0.0",
"reflux": "0.2.4",
"react-router": "~0.11.6",
"react": "~0.12.2"
"react": "~0.12.2",
"react-infinite": "~0.2.2"
}
}

View File

@ -10,21 +10,12 @@ var App = require('./components/App.jsx');
var Connect = require('./components/Connect.jsx');
var Chat = require('./components/Chat.jsx');
var Settings = require('./components/Settings.jsx');
var tabActions = require('./actions/tab');
var serverActions = require('./actions/server');
var channelActions = require('./actions/channel');
var uuid = localStorage.uuid || (localStorage.uuid = util.UUID());
var nick = 'test' + Math.floor(Math.random() * 99999);
socket.on('connect', function() {
socket.send('uuid', uuid);
/*serverActions.connect('irc.freenode.net', nick, 'username', true, 'Freenode');
serverActions.connect('irc.quakenet.org', nick, 'username', false, 'QuakeNet');
channelActions.join(['#stuff'], 'irc.freenode.net');
channelActions.join(['#herp'], 'irc.quakenet.org');*/
});
socket.on('error', function(error) {

View File

@ -17,7 +17,7 @@ var serverStore = Reflux.createStore({
server = server.slice(0, i);
}
servers[server] = {
servers[server] = {
address: server,
nick: nick,
username: username,

16
main.go
View File

@ -20,12 +20,22 @@ var (
)
func serveFiles(w http.ResponseWriter, r *http.Request) {
var ext string
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip")
ext = ".gz"
}
if strings.HasSuffix(r.URL.Path, "bundle.js") {
r.URL.Path = "/bundle.js"
w.Header().Set("Content-Type", "text/javascript")
r.URL.Path = "/bundle.js" + ext
} else if strings.HasSuffix(r.URL.Path, "style.css") {
r.URL.Path = "/style.css"
w.Header().Set("Content-Type", "text/css")
r.URL.Path = "/style.css" + ext
} else {
r.URL.Path = "/"
w.Header().Set("Content-Type", "text/html")
r.URL.Path = "/index.html" + ext
}
fs.ServeHTTP(w, r)