Skip to content

Commit 03ad7d3

Browse files
authored
Merge pull request #609 from CleanTalk/separation_js_bundles_av
Separation js bundles av
2 parents 726f437 + e399c9b commit 03ad7d3

27 files changed

Lines changed: 21338 additions & 1835 deletions

gulpfile.js

Lines changed: 105 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,70 +50,128 @@ function bundle_admin_and_common_js() {
5050
/**
5151
* Bundle Create
5252
*/
53-
// Bundle without external and internal js
53+
// Bundle with common-functions, without external and internal js
5454
function bundle_src_js() {
5555
return gulp.src([
56+
'js/src/apbct-common-functions.js',
5657
'js/src/apbct-public--0*.js',
5758
'js/src/apbct-public--1*.js',
5859
'js/src/apbct-public--2*.js',
5960
'js/src/apbct-public--3*.js',
6061
'js/src/apbct-public--7*.js',
61-
'js/src/apbct-common-functions.js',
6262
])
6363
// Unminified bundle
64-
.pipe(concat('apbct-public-bundle.js'))
64+
.pipe(concat('apbct-public-bundle_comm-func.js'))
6565
.pipe(gulp.dest('js/src/'));
6666
}
6767

68-
// Bundle with external js and without internal js
69-
function bundle_src_js_external_protection() {
68+
// Bundle without common-functions, external and internal js
69+
function bundle_src_js_without_cf() {
7070
return gulp.src([
71-
'js/src/apbct-public--0*.js',
72-
'js/src/apbct-public--1*.js',
73-
'js/src/apbct-public--2*.js',
74-
'js/src/apbct-public--3*.js',
75-
'js/src/apbct-public--7*.js',
76-
'js/src/apbct-public--5--external-forms.js',
77-
'js/src/apbct-common-functions.js',
78-
])
71+
'js/src/apbct-public--0*.js',
72+
'js/src/apbct-public--1*.js',
73+
'js/src/apbct-public--2*.js',
74+
'js/src/apbct-public--3*.js',
75+
'js/src/apbct-public--7*.js',
76+
])
7977
// Unminified bundle
80-
.pipe(concat('apbct-public-bundle_ext-protection.js'))
78+
.pipe(concat('apbct-public-bundle.js'))
8179
.pipe(gulp.dest('js/src/'));
8280
}
8381

84-
// Bundle with internal js and without external js
82+
// Bundle with common-functions, external js and without internal js
83+
function bundle_src_js_external_protection() {
84+
return gulp.src([
85+
'js/src/apbct-common-functions.js',
86+
'js/src/apbct-public--0*.js',
87+
'js/src/apbct-public--1*.js',
88+
'js/src/apbct-public--2*.js',
89+
'js/src/apbct-public--3*.js',
90+
'js/src/apbct-public--7*.js',
91+
'js/src/apbct-public--5--external-forms.js',
92+
])
93+
// Unminified bundle
94+
.pipe(concat('apbct-public-bundle_ext-protection_comm-func.js'))
95+
.pipe(gulp.dest('js/src/'));
96+
}
97+
98+
// Bundle with external js and without internal js, common-functions
99+
function bundle_src_js_external_protection_without_cf() {
100+
return gulp.src([
101+
'js/src/apbct-public--0*.js',
102+
'js/src/apbct-public--1*.js',
103+
'js/src/apbct-public--2*.js',
104+
'js/src/apbct-public--3*.js',
105+
'js/src/apbct-public--7*.js',
106+
'js/src/apbct-public--5--external-forms.js',
107+
])
108+
// Unminified bundle
109+
.pipe(concat('apbct-public-bundle_ext-protection.js'))
110+
.pipe(gulp.dest('js/src/'));
111+
}
112+
113+
// Bundle with common-functions, internal js and without external js
85114
function bundle_src_js_internal_protection() {
86115
return gulp.src([
87-
'js/src/apbct-common-functions.js',
88-
'js/src/apbct-public--0*.js',
89-
'js/src/apbct-public--1*.js',
90-
'js/src/apbct-public--2*.js',
91-
'js/src/apbct-public--3*.js',
92-
'js/src/apbct-public--7*.js',
93-
'js/src/apbct-public--6--internal-forms.js',
94-
'js/src/apbct-common-functions.js',
95-
])
96-
// Unminified bundle
97-
.pipe(concat('apbct-public-bundle_int-protection.js'))
98-
.pipe(gulp.dest('js/src/'));
116+
'js/src/apbct-common-functions.js',
117+
'js/src/apbct-public--0*.js',
118+
'js/src/apbct-public--1*.js',
119+
'js/src/apbct-public--2*.js',
120+
'js/src/apbct-public--3*.js',
121+
'js/src/apbct-public--7*.js',
122+
'js/src/apbct-public--6--internal-forms.js',
123+
])
124+
// Unminified bundle
125+
.pipe(concat('apbct-public-bundle_int-protection_comm-func.js'))
126+
.pipe(gulp.dest('js/src/'));
99127
}
100128

101-
// Bundle with external and internal js
102-
function bundle_src_js_ext_int_protection() {
129+
// Bundle with internal js and without external js, common-functions
130+
function bundle_src_js_internal_protection_without_cf() {
103131
return gulp.src([
104-
'js/src/apbct-common-functions.js',
105-
'js/src/apbct-public--0*.js',
106-
'js/src/apbct-public--1*.js',
107-
'js/src/apbct-public--2*.js',
108-
'js/src/apbct-public--3*.js',
109-
'js/src/apbct-public--7*.js',
110-
'js/src/apbct-public--5--external-forms.js',
111-
'js/src/apbct-public--6--internal-forms.js',
112-
'js/src/apbct-common-functions.js',
113-
])
114-
// Unminified bundle
115-
.pipe(concat('apbct-public-bundle_full-protection.js'))
116-
.pipe(gulp.dest('js/src/'));
132+
'js/src/apbct-public--0*.js',
133+
'js/src/apbct-public--1*.js',
134+
'js/src/apbct-public--2*.js',
135+
'js/src/apbct-public--3*.js',
136+
'js/src/apbct-public--7*.js',
137+
'js/src/apbct-public--6--internal-forms.js',
138+
])
139+
// Unminified bundle
140+
.pipe(concat('apbct-public-bundle_int-protection.js'))
141+
.pipe(gulp.dest('js/src/'));
142+
}
143+
144+
// Bundle with common-functions, external and internal js
145+
function bundle_src_js_full_protection() {
146+
return gulp.src([
147+
'js/src/apbct-common-functions.js',
148+
'js/src/apbct-public--0*.js',
149+
'js/src/apbct-public--1*.js',
150+
'js/src/apbct-public--2*.js',
151+
'js/src/apbct-public--3*.js',
152+
'js/src/apbct-public--7*.js',
153+
'js/src/apbct-public--5--external-forms.js',
154+
'js/src/apbct-public--6--internal-forms.js',
155+
])
156+
// Unminified bundle
157+
.pipe(concat('apbct-public-bundle_full-protection_comm-func.js'))
158+
.pipe(gulp.dest('js/src/'));
159+
}
160+
161+
// Bundle with external and internal js, without common-functions
162+
function bundle_src_js_full_protection_without_cf() {
163+
return gulp.src([
164+
'js/src/apbct-public--0*.js',
165+
'js/src/apbct-public--1*.js',
166+
'js/src/apbct-public--2*.js',
167+
'js/src/apbct-public--3*.js',
168+
'js/src/apbct-public--7*.js',
169+
'js/src/apbct-public--5--external-forms.js',
170+
'js/src/apbct-public--6--internal-forms.js',
171+
])
172+
// Unminified bundle
173+
.pipe(concat('apbct-public-bundle_full-protection.js'))
174+
.pipe(gulp.dest('js/src/'));
117175
}
118176

119177
function bundle_js() {
@@ -129,9 +187,13 @@ function bundle_js() {
129187

130188
gulp.task('compress-js', gulp.series(
131189
bundle_src_js,
190+
bundle_src_js_without_cf,
132191
bundle_src_js_external_protection,
192+
bundle_src_js_external_protection_without_cf,
133193
bundle_src_js_internal_protection,
134-
bundle_src_js_ext_int_protection,
194+
bundle_src_js_internal_protection_without_cf,
195+
bundle_src_js_full_protection,
196+
bundle_src_js_full_protection_without_cf,
135197
bundle_js,
136198
compress_all_js,
137199
bundle_admin_and_common_js

inc/cleantalk-public.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Cleantalk\ApbctWP\Variables\Post;
1010
use Cleantalk\ApbctWP\Variables\Server;
1111
use Cleantalk\ApbctWP\LinkConstructor;
12+
use Cleantalk\ApbctWP\ApbctJsBundleResolver;
1213

1314
/**
1415
* Init functions
@@ -1262,23 +1263,9 @@ function apbct_enqueue_and_localize_public_scripts()
12621263
global $apbct;
12631264

12641265
$in_footer = defined('CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER') && CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER;
1265-
12661266
// Different JS params
1267-
if (!$apbct->settings['forms__check_external'] && !$apbct->settings['forms__check_internal']) {
1268-
ApbctEnqueue::getInstance()->js('apbct-public-bundle.js', array(), $in_footer);
1269-
}
1270-
1271-
if ($apbct->settings['forms__check_external'] && !$apbct->settings['forms__check_internal']) {
1272-
ApbctEnqueue::getInstance()->js('apbct-public-bundle_ext-protection.js', array(), $in_footer);
1273-
}
1274-
1275-
if ($apbct->settings['forms__check_internal'] && !$apbct->settings['forms__check_external']) {
1276-
ApbctEnqueue::getInstance()->js('apbct-public-bundle_int-protection.js', array(), $in_footer);
1277-
}
1278-
1279-
if ($apbct->settings['forms__check_external'] && $apbct->settings['forms__check_internal']) {
1280-
ApbctEnqueue::getInstance()->js('apbct-public-bundle_full-protection.js', array(), $in_footer);
1281-
}
1267+
$bundle_name = ApbctJsBundleResolver::getBundleName($apbct->settings);
1268+
ApbctEnqueue::getInstance()->js($bundle_name, array(), $in_footer);
12821269

12831270
// Bot detector
12841271
if ( $apbct->settings['data__bot_detector_enabled'] && ! apbct_bot_detector_scripts_exclusion()) {

js/apbct-public-bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apbct-public-bundle.min.js.map

Lines changed: 0 additions & 5 deletions
This file was deleted.

js/apbct-public-bundle_comm-func.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apbct-public-bundle_comm-func.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apbct-public-bundle_ext-protection.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apbct-public-bundle_ext-protection.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apbct-public-bundle_ext-protection_comm-func.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apbct-public-bundle_ext-protection_comm-func.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)