Skip to content

Commit

Permalink
perf: gzip ui asserts
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Sep 14, 2021
1 parent 29a925d commit 2291340
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 0 deletions.
12 changes: 12 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"strconv"
"strings"
"time"

"rttys/cache"
Expand Down Expand Up @@ -571,6 +572,17 @@ func httpStart(br *broker) {
r.HandleContext(c)
return
}

if strings.Contains(c.Request.Header.Get("Accept-Encoding"), "gzip") {
if strings.HasSuffix(path, "css") || strings.HasSuffix(path, "js") {
magic := make([]byte, 2)
f.Read(magic)
if magic[0] == 0x1f && magic[1] == 0x8b {
c.Writer.Header().Set("Content-Encoding", "gzip")
}
}
}

f.Close()
}

Expand Down
216 changes: 216 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@vue/cli-plugin-typescript": "^4.5.12",
"@vue/cli-service": "^4.5.12",
"@vue/eslint-config-typescript": "^5.1.0",
"compression-webpack-plugin": "^6.1.1",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.32.12",
Expand Down
15 changes: 15 additions & 0 deletions ui/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const CompressionPlugin = require('compression-webpack-plugin')

module.exports = {
productionSourceMap: false,
pages: {
index: {
entry: 'src/main.ts',
Expand All @@ -13,6 +16,18 @@ module.exports = {
enableInSFC: false
}
},
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
return {
plugins: [new CompressionPlugin({
test: /\.js$|\.html$|\.css/,
threshold: 4096,
deleteOriginalAssets: true,
filename: '[path][base]?gz'
})]
}
}
},
devServer: {
proxy: {
'/devs': {
Expand Down

0 comments on commit 2291340

Please sign in to comment.