Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit cfec6d9

Browse files
committed
serve compressed files
1 parent 45a28de commit cfec6d9

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@polkadot/util-crypto": "^10.4.2",
3737
"bcryptjs": "^2.4.3",
3838
"bootstrap": "^5.2.3",
39+
"compression-webpack-plugin": "^10.0.0",
3940
"cookie-parser": "^1.4.6",
4041
"crypto-browserify": "^3.12.0",
4142
"dotenv": "^16.0.1",

api/src/backend/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ app.get("/", (req, res) => {
5252
res.redirect("/dapp");
5353
});
5454

55+
app.get("*.js", (req, res, next) => {
56+
req.url = req.url + '.gz';
57+
res.set('Content-Encoding', 'gzip');
58+
next();
59+
});
60+
5561
// uncaught error
5662
app.use(errorHandler(environment));
5763

api/src/frontend/webpack.config.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const path = require("path");
2-
var mode = process.env.NODE_ENV || 'development';
2+
const TerserPlugin = require("terser-webpack-plugin");
3+
const CompressionPlugin = require("compression-webpack-plugin");
4+
5+
var mode = process.env.NODE_ENV || "development";
36

47
module.exports = {
58
entry: {
@@ -64,8 +67,17 @@ module.exports = {
6467
path: path.resolve(__dirname, "../../public/lib"),
6568
},
6669
mode: mode,
67-
watchOptions: {
68-
poll: true
70+
// watchOptions: {
71+
// poll: true,
72+
// },
73+
optimization: {
74+
splitChunks: {
75+
chunks: 'async'
76+
},
77+
minimize: true,
78+
minimizer: [new TerserPlugin()],
6979
},
70-
plugins: []
80+
plugins: [
81+
new CompressionPlugin({deleteOriginalAssets: true, threshold:10240, minRatio:0.8}),
82+
],
7183
};

api/yarn.lock

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,6 +7797,14 @@ compressible@~2.0.14, compressible@~2.0.16:
77977797
dependencies:
77987798
mime-db ">= 1.43.0 < 2"
77997799

7800+
compression-webpack-plugin@^10.0.0:
7801+
version "10.0.0"
7802+
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-10.0.0.tgz#3496af1b0dc792e13efc474498838dbff915c823"
7803+
integrity sha512-wLXLIBwpul/ALcm7Aj+69X0pYT3BYt6DdPn3qrgBIh9YejV9Bju9ShhlAsjujLyWMo6SAweFIWaUoFmXZNuNrg==
7804+
dependencies:
7805+
schema-utils "^4.0.0"
7806+
serialize-javascript "^6.0.0"
7807+
78007808
compression@1.7.3:
78017809
version "1.7.3"
78027810
resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.3.tgz#27e0e176aaf260f7f2c2813c3e440adb9f1993db"
@@ -12559,9 +12567,9 @@ media-typer@0.3.0:
1255912567
integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==
1256012568

1256112569
memfs@^3.1.2, memfs@^3.4.3:
12562-
version "3.4.13"
12563-
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.4.13.tgz#248a8bd239b3c240175cd5ec548de5227fc4f345"
12564-
integrity sha512-omTM41g3Skpvx5dSYeZIbXKcXoAVc/AoMNwn9TKx++L/gaen/+4TTttmu8ZSch5vfVJ8uJvGbroTsIlslRg6lg==
12570+
version "3.5.0"
12571+
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.5.0.tgz#9da86405fca0a539addafd37dbd452344fd1c0bd"
12572+
integrity sha512-yK6o8xVJlQerz57kvPROwTMgx5WtGwC2ZxDtOUsnGl49rHjYkfQoPNZPCKH73VdLE1BwBu/+Fx/NL8NYMUw2aA==
1256512573
dependencies:
1256612574
fs-monkey "^1.0.3"
1256712575

0 commit comments

Comments
 (0)