Skip to content

Commit f5047d4

Browse files
committed
feat(js): combine and minify all JS files into one to improve load speed
1 parent 2d597ab commit f5047d4

File tree

8 files changed

+58
-16
lines changed

8 files changed

+58
-16
lines changed

Diff for: gulpfile.babel.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import cssnano from "cssnano";
1010
import postcssPresetEnv from "postcss-preset-env";
1111
import rfs from "rfs";
1212
import concat from "gulp-concat";
13+
import terser from "gulp-terser";
1314

1415
const browserSync = browserSyncCreate();
1516

@@ -65,9 +66,10 @@ const watchFiles = () => {
6566
"static/**/*.css",
6667
"static/**/*.less",
6768
"!static/**/elegant.prod.css",
69+
"static/**/*.js",
70+
"!static/js/elegant.prod.js",
6871
"!static/**/bootstrap.css",
69-
"!static/**/bootstrap_responsive.css",
70-
"static/**/*.js"
72+
"!static/**/bootstrap_responsive.css"
7173
],
7274
{ ignoreInitial: false },
7375
buildAll
@@ -81,6 +83,17 @@ const rmProdCSS = cb => {
8183
}
8284
cb();
8385
};
86+
const minifyJS = () => {
87+
return src([
88+
"static/tipuesearch/tipuesearch_set.js",
89+
"static/tipuesearch/tipuesearch.min.js",
90+
"static/applause-button/applause-button.js",
91+
"!static/js/elegant.prod.js"
92+
])
93+
.pipe(concat("elegant.prod.js"))
94+
.pipe(terser())
95+
.pipe(dest("static/js/"));
96+
};
8497

8598
const compileCSS = () => {
8699
const plugins = [
@@ -106,12 +119,14 @@ const buildAll = series(
106119
compileBootstrapLess,
107120
compileResponsiveLess,
108121
compileCSS,
122+
minifyJS,
109123
buildContent
110124
);
111125
const elegant = series(
112126
compileBootstrapLess,
113127
compileResponsiveLess,
114128
compileCSS,
129+
minifyJS,
115130
cleanOutput,
116131
buildContent,
117132
parallel(watchFiles, reload)

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"gulp-concat": "^2.6.1",
1414
"gulp-postcss": "^8.0.0",
1515
"gulp-run-command": "^0.0.10",
16+
"gulp-terser": "^1.2.0",
1617
"postcss-font-magician": "^2.3.1",
1718
"postcss-preset-env": "^6.7.0",
1819
"recess": "^1.1.9",

Diff for: static/js/elegant.prod.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: templates/_includes/applause_button.html

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
{% set identifier = article.applause_button_id %}
1010
{% endif %}
1111

12-
<script src="{{ SITEURL }}/theme/applause-button/applause-button.js"></script>
1312
<div class="applause_button">
1413
<applause-button url={{ identifier }}> </applause-button>
1514
</div>

Diff for: templates/_includes/minify_tipuesearch.html

-3
This file was deleted.

Diff for: templates/base.html

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
{% endif %}
104104
<script src="//code.jquery.com/jquery.min.js"></script>
105105
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
106+
<script src="{{ SITEURL }}/theme/js/elegant.prod.js"></script>
106107
<script>
107108
function validateForm(query)
108109
{

Diff for: templates/search.html

-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@
3232

3333
{% block script %}
3434
{{ super() }}
35-
{% if 'assets' in PLUGINS %}
36-
{% include '_includes/minify_tipuesearch.html' with context %}
37-
{% else %}
38-
<script src="{{ SITEURL }}/theme/tipuesearch/tipuesearch_set.js"></script>
39-
<script src="{{ SITEURL }}/theme/tipuesearch/tipuesearch.min.js"></script>
40-
{% endif %}
41-
4235
{% if 'tipue_search' in PLUGINS %}
4336
<script src="{{ SITEURL }}/tipuesearch_content.js"></script>
4437
{% endif %}

Diff for: yarn.lock

+30-3
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
18601860
dependencies:
18611861
delayed-stream "~1.0.0"
18621862

1863-
commander@^2.2.0, commander@~2.20.3:
1863+
commander@^2.2.0, commander@^2.20.0, commander@~2.20.3:
18641864
version "2.20.3"
18651865
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
18661866
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@@ -3664,6 +3664,16 @@ gulp-run-command@^0.0.10:
36643664
spawn-args "0.2.0"
36653665
timeout-as-promise "^1.0.0"
36663666

3667+
gulp-terser@^1.2.0:
3668+
version "1.2.0"
3669+
resolved "https://registry.yarnpkg.com/gulp-terser/-/gulp-terser-1.2.0.tgz#41df2a1d0257d011ba8b05efb2568432ecd0495b"
3670+
integrity sha512-lf+jE2DALg2w32p0HRiYMlFYRYelKZPNunHp2pZccCYrrdCLOs0ItbZcN63yr2pbz116IyhUG9mD/QbtRO1FKA==
3671+
dependencies:
3672+
plugin-error "^1.0.1"
3673+
terser "^4.0.0"
3674+
through2 "^3.0.1"
3675+
vinyl-sourcemaps-apply "^0.2.1"
3676+
36673677
gulp@^4.0.2:
36683678
version "4.0.2"
36693679
resolved "https://registry.yarnpkg.com/gulp/-/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa"
@@ -8152,6 +8162,14 @@ source-map-support@^0.4.15:
81528162
dependencies:
81538163
source-map "^0.5.6"
81548164

8165+
source-map-support@~0.5.12:
8166+
version "0.5.16"
8167+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042"
8168+
integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==
8169+
dependencies:
8170+
buffer-from "^1.0.0"
8171+
source-map "^0.6.0"
8172+
81558173
source-map-url@^0.4.0:
81568174
version "0.4.0"
81578175
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -8162,7 +8180,7 @@ source-map@^0.5.1, source-map@^0.5.6, source-map@^0.5.7:
81628180
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
81638181
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
81648182

8165-
source-map@^0.6.1, source-map@~0.6.1:
8183+
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
81668184
version "0.6.1"
81678185
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
81688186
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@@ -8593,6 +8611,15 @@ term-size@^1.2.0:
85938611
dependencies:
85948612
execa "^0.7.0"
85958613

8614+
terser@^4.0.0:
8615+
version "4.6.3"
8616+
resolved "https://registry.yarnpkg.com/terser/-/terser-4.6.3.tgz#e33aa42461ced5238d352d2df2a67f21921f8d87"
8617+
integrity sha512-Lw+ieAXmY69d09IIc/yqeBqXpEQIpDGZqT34ui1QWXIUpR2RjbqEkT8X7Lgex19hslSqcWM5iMN2kM11eMsESQ==
8618+
dependencies:
8619+
commander "^2.20.0"
8620+
source-map "~0.6.1"
8621+
source-map-support "~0.5.12"
8622+
85968623
text-extensions@^1.0.0:
85978624
version "1.9.0"
85988625
resolved "https://registry.yarnpkg.com/text-extensions/-/text-extensions-1.9.0.tgz#1853e45fee39c945ce6f6c36b2d659b5aabc2a26"
@@ -8627,7 +8654,7 @@ through2@^2.0.0, through2@^2.0.2, through2@^2.0.3, through2@~2.0.0:
86278654
readable-stream "~2.3.6"
86288655
xtend "~4.0.1"
86298656

8630-
through2@^3.0.0:
8657+
through2@^3.0.0, through2@^3.0.1:
86318658
version "3.0.1"
86328659
resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a"
86338660
integrity sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==

0 commit comments

Comments
 (0)