Skip to content

Commit fda34be

Browse files
committed
refactor(core): serve gzip static files in production
1 parent 001e7c6 commit fda34be

File tree

7 files changed

+128
-23
lines changed

7 files changed

+128
-23
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Logs
22
*.log
33

4+
#compressed files
5+
*.gz
6+
47
# Runtime data
58
pids
69
*.pid

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"cheerio": "1.0.0-rc.10",
3737
"clone": "2.1.2",
3838
"clsx": "1.1.1",
39+
"compression": "1.7.4",
3940
"connect-flash": "0.1.1",
4041
"connect-mongo": "4.6.0",
4142
"cookie": "0.4.2",
@@ -49,6 +50,7 @@
4950
"express": "4.17.3",
5051
"express-hbs": "2.4.0",
5152
"express-session": "1.17.2",
53+
"express-static-gzip": "2.1.7",
5254
"fast-csv": "4.3.6",
5355
"fs-extra": "10.0.0",
5456
"handlebars": "4.7.7",
@@ -145,6 +147,7 @@
145147
"babel-loader": "8.2.3",
146148
"chai": "*",
147149
"codacy-coverage": "3.0.0",
150+
"compression-webpack-plugin": "10.0.0",
148151
"cross-env": "7.0.3",
149152
"css-loader": "6.6.0",
150153
"eslint": "8.9.0",

src/client/containers/Topbar/profileDropdown.jsx

Whitespace-only changes.

src/middleware/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const path = require('path')
1616
const async = require('async')
1717
const express = require('express')
18+
const expressStaticGzip = require('express-static-gzip')
1819
const mongoose = require('mongoose')
1920
const APC = require('@handlebars/allow-prototype-access')
2021
const HandleBars = require('handlebars')
@@ -55,7 +56,8 @@ module.exports = function (app, db, callback) {
5556
app.use(bodyParser.json({ limit: '2mb' }))
5657
app.use(cookieParser())
5758

58-
app.use(express.static(path.join(__dirname, '../../public')))
59+
if (process.env.NODE_ENV === 'production') app.use(expressStaticGzip(path.join(__dirname, '../../public')))
60+
else app.use(express.static(path.join(__dirname, '../../public')))
5961

6062
app.use(function (req, res, next) {
6163
if (mongoose.connection.readyState !== 1) {

src/sass/partials/profileDrop.sass

Whitespace-only changes.

webpack.config.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var path = require('path')
2-
var webpack = require('webpack')
3-
var MiniCssExtractPlugin = require('mini-css-extract-plugin')
4-
var TerserPlugin = require('terser-webpack-plugin')
5-
const HtmlWebpackPlugin = require('html-webpack-plugin')
1+
const path = require('path')
2+
const webpack = require('webpack')
3+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
4+
const TerserPlugin = require('terser-webpack-plugin')
5+
const CompressionPlugin = require('compression-webpack-plugin')
66

77
module.exports = {
88
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
@@ -40,8 +40,6 @@ module.exports = {
4040
moment_timezone: 'vendor/moment/moment-timezone-with-data',
4141
uikit: 'vendor/uikit/js/uikit_combined.min',
4242
modernizr: 'vendor/modernizr/modernizr',
43-
fastclick: 'vendor/fastclick/fastclick',
44-
placeholder: 'vendor/placeholder/placeholder',
4543
underscore: 'vendor/underscore/underscore',
4644
history: 'vendor/history/jquery.history',
4745
app: 'app',
@@ -72,7 +70,6 @@ module.exports = {
7270
waves: 'vendor/waves/waves',
7371
isinview: 'plugins/jquery.isinview',
7472
jquery_docsize: 'plugins/jquery.documentsize',
75-
idletimer: 'plugins/jquery.idletimer.js',
7673
jquery_steps: 'plugins/jquery.steps',
7774
jquery_actual: 'plugins/jquery.actual',
7875
formvalidator: 'vendor/formvalidator/jquery.form-validator',
@@ -196,9 +193,7 @@ module.exports = {
196193
new MiniCssExtractPlugin({
197194
filename: 'app.min.css'
198195
}),
199-
new HtmlWebpackPlugin({
200-
template: 'src/client/index.html'
201-
})
196+
new CompressionPlugin()
202197
],
203198
performance: {
204199
hints: 'warning',

yarn.lock

+113-11
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ accepts@~1.3.4:
25912591
mime-types "~2.1.18"
25922592
negotiator "0.6.1"
25932593

2594-
accepts@~1.3.8:
2594+
accepts@~1.3.5, accepts@~1.3.8:
25952595
version "1.3.8"
25962596
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e"
25972597
integrity sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==
@@ -3657,6 +3657,11 @@ bytes@1:
36573657
resolved "https://registry.yarnpkg.com/bytes/-/bytes-1.0.0.tgz#3569ede8ba34315fab99c3e92cb04c7220de1fa8"
36583658
integrity sha1-NWnt6Lo0MV+rmcPpLLBMciDeH6g=
36593659

3660+
3661+
version "3.0.0"
3662+
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
3663+
integrity sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==
3664+
36603665
36613666
version "3.1.0"
36623667
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
@@ -4391,6 +4396,34 @@ compress-commons@^4.1.0:
43914396
normalize-path "^3.0.0"
43924397
readable-stream "^3.6.0"
43934398

4399+
compressible@~2.0.16:
4400+
version "2.0.18"
4401+
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"
4402+
integrity sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==
4403+
dependencies:
4404+
mime-db ">= 1.43.0 < 2"
4405+
4406+
4407+
version "10.0.0"
4408+
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-10.0.0.tgz#3496af1b0dc792e13efc474498838dbff915c823"
4409+
integrity sha512-wLXLIBwpul/ALcm7Aj+69X0pYT3BYt6DdPn3qrgBIh9YejV9Bju9ShhlAsjujLyWMo6SAweFIWaUoFmXZNuNrg==
4410+
dependencies:
4411+
schema-utils "^4.0.0"
4412+
serialize-javascript "^6.0.0"
4413+
4414+
4415+
version "1.7.4"
4416+
resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f"
4417+
integrity sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==
4418+
dependencies:
4419+
accepts "~1.3.5"
4420+
bytes "3.0.0"
4421+
compressible "~2.0.16"
4422+
debug "2.6.9"
4423+
on-headers "~1.0.2"
4424+
safe-buffer "5.1.2"
4425+
vary "~1.1.2"
4426+
43944427
43954428
version "0.0.1"
43964429
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -5067,21 +5100,26 @@ denque@^2.0.1:
50675100
resolved "https://registry.yarnpkg.com/denque/-/denque-2.0.1.tgz#bcef4c1b80dc32efe97515744f21a4229ab8934a"
50685101
integrity sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==
50695102

5103+
[email protected], depd@~2.0.0:
5104+
version "2.0.0"
5105+
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
5106+
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
5107+
50705108
depd@^1.1.2, depd@~1.1.2:
50715109
version "1.1.2"
50725110
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9"
50735111
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=
50745112

5075-
depd@~2.0.0:
5076-
version "2.0.0"
5077-
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
5078-
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
5079-
50805113
deprecation@^2.0.0, deprecation@^2.3.1:
50815114
version "2.3.1"
50825115
resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919"
50835116
integrity sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==
50845117

5118+
5119+
version "1.2.0"
5120+
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015"
5121+
integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==
5122+
50855123
destroy@~1.0.4:
50865124
version "1.0.4"
50875125
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
@@ -6335,6 +6373,13 @@ [email protected]:
63356373
safe-buffer "5.2.1"
63366374
uid-safe "~2.1.5"
63376375

6376+
6377+
version "2.1.7"
6378+
resolved "https://registry.yarnpkg.com/express-static-gzip/-/express-static-gzip-2.1.7.tgz#5904824a07950ba741ec3a23a21839dd04c63506"
6379+
integrity sha512-QOCZUC+lhPPCjIJKpQGu1Oa61Axg9Mq09Qvit8Of7kzpMuwDeMSqjjQteQS3OVw/GkENBoSBheuQDWPlngImvw==
6380+
dependencies:
6381+
serve-static "^1.14.1"
6382+
63386383
63396384
version "4.17.3"
63406385
resolved "https://registry.yarnpkg.com/express/-/express-4.17.3.tgz#f6c7302194a4fb54271b73a1fe7a06478c8f85a1"
@@ -7868,6 +7913,17 @@ [email protected]:
78687913
statuses ">= 1.5.0 < 2"
78697914
toidentifier "1.0.1"
78707915

7916+
7917+
version "2.0.0"
7918+
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3"
7919+
integrity sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==
7920+
dependencies:
7921+
depd "2.0.0"
7922+
inherits "2.0.4"
7923+
setprototypeof "1.2.0"
7924+
statuses "2.0.1"
7925+
toidentifier "1.0.1"
7926+
78717927
http-parser-js@>=0.4.0:
78727928
version "0.5.0"
78737929
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.0.tgz#d65edbede84349d0dc30320815a15d39cc3cbbd8"
@@ -10223,6 +10279,11 @@ [email protected]:
1022310279
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.51.0.tgz#d9ff62451859b18342d960850dc3cfb77e63fb0c"
1022410280
integrity sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==
1022510281

10282+
"mime-db@>= 1.43.0 < 2":
10283+
version "1.52.0"
10284+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
10285+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
10286+
1022610287
mime-db@~1.37.0:
1022710288
version "1.37.0"
1022810289
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.37.0.tgz#0b6a0ce6fdbe9576e25f1f2d2fde8830dc0ad0d8"
@@ -11338,6 +11399,13 @@ object.values@^1.1.4, object.values@^1.1.5:
1133811399
define-properties "^1.1.3"
1133911400
es-abstract "^1.19.1"
1134011401

11402+
11403+
version "2.4.1"
11404+
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f"
11405+
integrity sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==
11406+
dependencies:
11407+
ee-first "1.1.1"
11408+
1134111409
on-finished@~2.3.0:
1134211410
version "2.3.0"
1134311411
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"
@@ -13552,16 +13620,16 @@ [email protected]:
1355213620
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"
1355313621
integrity sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==
1355413622

13623+
[email protected], safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
13624+
version "5.1.2"
13625+
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
13626+
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
13627+
1355513628
[email protected], safe-buffer@^5.2.1:
1355613629
version "5.2.1"
1355713630
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
1355813631
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
1355913632

13560-
safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
13561-
version "5.1.2"
13562-
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
13563-
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
13564-
1356513633
safe-json-parse@~1.0.1:
1356613634
version "1.0.1"
1356713635
resolved "https://registry.yarnpkg.com/safe-json-parse/-/safe-json-parse-1.0.1.tgz#3e76723e38dfdda13c9b1d29a1e07ffee4b30b57"
@@ -13814,6 +13882,25 @@ [email protected]:
1381413882
range-parser "~1.2.1"
1381513883
statuses "~1.5.0"
1381613884

13885+
13886+
version "0.18.0"
13887+
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
13888+
integrity sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==
13889+
dependencies:
13890+
debug "2.6.9"
13891+
depd "2.0.0"
13892+
destroy "1.2.0"
13893+
encodeurl "~1.0.2"
13894+
escape-html "~1.0.3"
13895+
etag "~1.8.1"
13896+
fresh "0.5.2"
13897+
http-errors "2.0.0"
13898+
mime "1.6.0"
13899+
ms "2.1.3"
13900+
on-finished "2.4.1"
13901+
range-parser "~1.2.1"
13902+
statuses "2.0.1"
13903+
1381713904
[email protected], serialize-javascript@^6.0.0:
1381813905
version "6.0.0"
1381913906
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.0.tgz#efae5d88f45d7924141da8b5c3a7a7e663fefeb8"
@@ -13842,6 +13929,16 @@ [email protected]:
1384213929
parseurl "~1.3.3"
1384313930
send "0.17.2"
1384413931

13932+
serve-static@^1.14.1:
13933+
version "1.15.0"
13934+
resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.15.0.tgz#faaef08cffe0a1a62f60cad0c4e513cff0ac9540"
13935+
integrity sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==
13936+
dependencies:
13937+
encodeurl "~1.0.2"
13938+
escape-html "~1.0.3"
13939+
parseurl "~1.3.3"
13940+
send "0.18.0"
13941+
1384513942
set-blocking@^2.0.0:
1384613943
version "2.0.0"
1384713944
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
@@ -14415,6 +14512,11 @@ static-module@^3.0.2:
1441514512
static-eval "^2.0.5"
1441614513
through2 "~2.0.3"
1441714514

14515+
14516+
version "2.0.1"
14517+
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
14518+
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==
14519+
1441814520
"statuses@>= 1.5.0 < 2", statuses@~1.5.0:
1441914521
version "1.5.0"
1442014522
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"

0 commit comments

Comments
 (0)