PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | js/minify.js +131 -90 3.5.0 → 4.7.0 View file →
@@ -74,9 +74,8 @@
74 74 }).always(function() {
75 75 $.unblockUI();
76 76 });
77 77 });
78 -
79 78
80 79 // ======= SLIDERS ========
81 80 // Generic slider save
82 81 $('#wp-optimize-nav-tab-wpo_minify-status-contents form :input, #wp-optimize-nav-tab-wpo_minify-js-contents form :input, #wp-optimize-nav-tab-wpo_minify-css-contents form :input, #wp-optimize-nav-tab-wpo_minify-font-contents form :input, #wp-optimize-nav-tab-wpo_minify-analytics-contents form :input, #wp-optimize-nav-tab-wpo_minify-settings-contents form :input, #wp-optimize-nav-tab-wpo_minify-advanced-contents form :input').on('change', function() {
@@ -115,22 +114,41 @@
115 114 $('#wpo_min_enable_minify').on('wp-optimize/minify/saved_setting', function() {
116 115
117 116 $(this).closest('.wpo_section').toggleClass('wpo-feature-is-disabled', !$(this).is(':checked'));
118 117 });
119 -
118 +
120 119 // Toggle wpo-feature-is-disabled class
121 120 $('#wpo_min_enable_minify_css, #wpo_min_enable_minify_js')
122 - // Set value on status change
121 + // Update UI when setting is saved
123 122 .on('wp-optimize/minify/saved_setting', function() {
124 - $('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="' + $(this).data('tabname') + '"] span.disabled').toggleClass('hidden', $(this).is(':checked'));
125 - $('#wpo_section_' + $(this).data('tabname')).toggleClass('wpo-disabled-section', $(this).is(':not(:checked)'));
123 + toggle_minify_tab_section($(this));
126 124 })
127 - // Set value on page load
125 + // Initialize UI on page load
128 126 .each(function() {
129 - $('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="' + $(this).data('tabname') + '"] span.disabled').toggleClass('hidden', $(this).is(':checked'));
130 - $('#wpo_section_' + $(this).data('tabname')).toggleClass('wpo-disabled-section', $(this).is(':not(:checked)'));
127 + toggle_minify_tab_section($(this));
131 128 });
132 -
129 +
130 + /**
131 + * Toggle the UI state of a minify tab section based on the associated checkbox state.
132 + *
133 + * - For JS minification, only elements marked with `.show-if-enabled` are toggled.
134 + *
135 + * @param {jQuery} $el The checkbox element controlling the minified setting
136 + *
137 + * @return {void}
138 + */
139 + function toggle_minify_tab_section($el) {
140 + var tab_name = $el.data('tabname');
141 + var tab_id = '#wpo_section_' + tab_name;
142 + var is_checked = $el.is(':checked');
143 +
144 + var $section = $el.is('#wpo_min_enable_minify_js') ? $(tab_id + ' .show-if-enabled') : $(tab_id);
145 +
146 + $('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="' + tab_name + '"] span.disabled').toggleClass('hidden', is_checked);
147 +
148 + $section.toggleClass('wpo-disabled-section', !is_checked);
149 + }
150 +
133 151 // slider enable Debug mode
134 152 $('#wpo_min_enable_minify_debug').on('wp-optimize/minify/saved_setting', function() {
135 153 // Refresh the page as it's needed to show the extra options
136 154 block_ui(wpoptimize.page_refresh);
@@ -145,9 +163,9 @@
145 163
146 164 var disable_google_fonts_processing = $('#disable_google_fonts_processing');
147 165
148 166 function handle_disable_google_fonts_processing() {
149 - $('#wp-optimize-nav-tab-wpo_minify-font-contents .google_fonts_option').prop('disabled', disable_google_fonts_processing.is(':checked'));
167 + $('#wp-optimize-nav-tab-wpo_minify-font-contents .google_fonts_option:not(.skip-disable-processing)').prop('disabled', disable_google_fonts_processing.is(':checked'));
150 168 }
151 169
152 170 disable_google_fonts_processing.on('change', handle_disable_google_fonts_processing);
153 171
@@ -164,8 +182,13 @@
164 182 spinner.show();
165 183 block_ui(wpoptimize.saving);
166 184
167 185 var data = {};
186 +
187 + var merge_state = {
188 + js: null,
189 + css: null
190 + };
168 191
169 192 var tabs = $('[data-whichpage="wpo_minify"] .wp-optimize-nav-tab-contents form');
170 193 tabs.each(function() {
171 194 var tab = $(this);
@@ -171,8 +194,16 @@
171 194 var tab = $(this);
172 195 if (true === tab.data('need_saving')) {
173 196 data = Object.assign(data, gather_data(tab));
174 197 tab.data('need_saving', false);
198 +
199 + if (typeof data.enable_merging_of_js !== 'undefined') {
200 + merge_state.js = data.enable_merging_of_js === 'true';
201 + }
202 +
203 + if (typeof data.enable_merging_of_css !== 'undefined') {
204 + merge_state.css = data.enable_merging_of_css === 'true';
205 + }
175 206 }
176 207 });
177 208
178 209 send_command('save_minify_settings', data, function(response) {
@@ -187,8 +218,14 @@
187 218 if (response.hasOwnProperty('files')) {
188 219 minify.updateFilesLists(response.files);
189 220 minify.updateStats(response.files);
190 221 }
222 +
223 + $.each(merge_state, function(type, enabled) {
224 + if (null !== enabled) {
225 + toggle_minify_notice(type, enabled, false);
226 + }
227 + });
191 228
192 229 spinner.hide();
193 230 success_icon.show();
194 231 setTimeout(function() {
@@ -199,14 +236,53 @@
199 236 }).always(function() {
200 237 $.unblockUI();
201 238 });
202 239 })
203 -
240 +
204 241 // Dismiss information notice
205 - $('.wp-optimize-minify-status-information-notice').on('click', '.notice-dismiss', function(e) {
242 + $('.wpo_section_notice_minify').on('click', '.notice-dismiss', function(e) {
206 243 e.preventDefault();
207 - send_command('hide_minify_notice');
244 + toggle_minify_notice('minify', null, true);
208 245 });
246 +
247 + $('.wpo_section_notice_js').on('click', '.notice-dismiss', function(e) {
248 + e.preventDefault();
249 + toggle_minify_notice('js', null, true);
250 + });
251 +
252 + $('.wpo_section_notice_css').on('click', '.notice-dismiss', function(e) {
253 + e.preventDefault();
254 + toggle_minify_notice('css', null, true);
255 + });
256 +
257 + /**
258 + * Toggle visibility of a WP-Optimize minify notice and persist user preference.
259 + *
260 + * @param {string} type - Notice type ('minify', 'js', 'css').
261 + * @param {boolean|null} merging_enabled - Whether the JS/CSS merging checkbox is enabled (true = checked, false = unchecked, null = not applicable).
262 + * @param {boolean} force_hide - Whether to hide forcefully (true) or (false).
263 + *
264 + * @returns {void}
265 + */
266 + function toggle_minify_notice(type, merging_enabled, force_hide) {
267 + var $notice = $('.wpo_section_notice_' + type);
268 + if (!$notice.length) return;
269 +
270 + send_command('toggle_minify_notice', { type: type, merging_enabled: merging_enabled, force_hide: force_hide }, function(response) {
271 + if (response.hasOwnProperty('success') && response.success === true) {
272 + if (response.hasOwnProperty('hide') && response.hide === true) {
273 + $notice.stop(true, true).slideUp(300);
274 + }
275 +
276 + if (response.hasOwnProperty('hide') && response.hide === false) {
277 + $notice.stop(true, true).slideDown(300);
278 + }
279 + }
280 + if (response.hasOwnProperty('message') && response.success !== true) {
281 + wp_optimize.notices.show_notice('error', response.message);
282 + }
283 + });
284 + }
209 285
210 286 // Show logs
211 287 $('#wpo_min_jsprocessed, #wpo_min_cssprocessed').on('click', '.log', function(e) {
212 288 e.preventDefault();
@@ -216,9 +292,9 @@
216 292 $(this).text(wpoptimize.hide_information);
217 293 } else {
218 294 $(this).text(wpoptimize.show_information);
219 295 }
220 - });
296 + });
221 297
222 298 // Delete log file
223 299 $('#wpo_min_jsprocessed, #wpo_min_cssprocessed').on('click', '.delete-file', function(e) {
224 300 e.preventDefault();
@@ -246,28 +322,8 @@
246 322 $.unblockUI();
247 323 });
248 324 });
249 325
250 - // Handle js excludes
251 - $('#wpo_min_jsprocessed').on('click', '.exclude', function(e) {
252 - e.preventDefault();
253 - var el = $(this);
254 - var excluded_file = get_excluded_file(el);
255 - add_excluded_js_file(excluded_file);
256 - tab_need_saving('js');
257 - highlight_excluded_item(el);
258 - });
259 -
260 - // Handle css excludes
261 - $('#wpo_min_cssprocessed').on('click', '.exclude', function(e) {
262 - e.preventDefault();
263 - var el = $(this);
264 - var excluded_file = get_excluded_file(el);
265 - add_excluded_css_file(excluded_file);
266 - tab_need_saving('css');
267 - highlight_excluded_item(el);
268 - });
269 -
270 326 // Trigger combined meta.json file download
271 327 $('.wpo-minify-download-metas-button').on('click', function(e) {
272 328 e.preventDefault();
273 329 send_command('get_minify_meta_files', null, function(response) {
@@ -284,83 +340,68 @@
284 340 link.click();
285 341 })
286 342 });
287 343
288 - /**
289 - * Get excluded file url
290 - *
291 - * @param {HTMLElement} el
292 - *
293 - * @return {string}
294 - */
295 - function get_excluded_file(el) {
296 - return el.data('url');
297 - }
344 + // Handle js excludes
345 + $('#wpo_min_jsprocessed').on('click', '.exclude', function(e) {
346 + e.preventDefault();
347 + get_url_and_tab_saving($(this), '#exclude_js', 'js');
348 + });
298 349
299 - /**
300 - * Exclude js file
301 - *
302 - * @param {string} excluded_file File url
303 - */
304 - function add_excluded_js_file(excluded_file) {
305 - var $js_textarea = $('#exclude_js');
306 - var list_of_excluded_files = $js_textarea.val();
307 - list_of_excluded_files += excluded_file + '\n';
308 - $js_textarea.val(list_of_excluded_files);
309 - }
350 + // Handle css excludes
351 + $('#wpo_min_cssprocessed').on('click', '.exclude', function(e) {
352 + e.preventDefault();
353 + get_url_and_tab_saving($(this), '#exclude_css', 'css');
354 + });
310 355
311 - /**
312 - * Exclude css file
313 - *
314 - * @param {string} excluded_file File url
315 - */
316 - function add_excluded_css_file(excluded_file) {
317 - var $css_textarea = $('#exclude_css');
318 - var list_of_excluded_files = $css_textarea.val();
319 - list_of_excluded_files += excluded_file + '\n';
320 - $css_textarea.val(list_of_excluded_files);
321 - }
322 -
323 356 // Handle defer
324 357 $('#wpo_min_jsprocessed').on('click', '.defer', function(e) {
325 358 e.preventDefault();
326 - add_deferred_file($(this));
359 + get_url_and_tab_saving($(this), '#async_js', 'js');
327 360 });
328 361
329 362 // Handle async loading
330 363 $('#wpo_min_cssprocessed').on('click', '.async', function(e) {
331 364 e.preventDefault();
332 - add_async_file($(this));
365 + get_url_and_tab_saving($(this), '#async_css', 'css');
333 366 });
334 -
367 +
335 368 /**
336 - * Add deferred file
369 + * Get url from an element and then save it
337 370 *
338 - * @param {HTMLElement} el target element
371 + * @param {HTMLElement} el
372 + * @param {string} target_el_id
373 + * @param {string} tab_name
374 + *
375 + * @return void
339 376 */
340 - function add_deferred_file(el) {
341 - var deferred_file = el.data('url');
342 - var $async_js_textarea = $('#async_js');
343 - var list_of_deferred_files = $async_js_textarea.val();
344 - list_of_deferred_files += deferred_file + '\n';
345 - $async_js_textarea.val(list_of_deferred_files);
346 - tab_need_saving('js');
377 + function get_url_and_tab_saving(el, target_el_id, tab_name) {
378 + var file_url = el.data('url');
379 + if ('' === file_url || undefined === file_url) {
380 + return;
381 + }
382 +
383 + add_url_to_next_line(target_el_id, file_url);
384 + tab_need_saving(tab_name);
347 385 highlight_excluded_item(el);
348 386 }
349 -
387 +
350 388 /**
351 - * Add asynchronously loading file
389 + * Add url to the next line of the element textarea
352 390 *
353 - * @param {HTMLElement} el target element
391 + * @param {string} target_el_id
392 + * @param {string} file_url
393 + *
394 + * @return void
354 395 */
355 - function add_async_file(el) {
356 - var async_file = el.data('url');
357 - var $async_css_textarea = $('#async_css');
358 - var list_of_async_files = $async_css_textarea.val();
359 - list_of_async_files += async_file + '\n';
360 - $async_css_textarea.val(list_of_async_files);
361 - tab_need_saving('css');
362 - highlight_excluded_item(el);
396 + function add_url_to_next_line(target_el_id, file_url) {
397 + var $textarea = $(target_el_id);
398 + var list_of_files = $textarea.val().trim();
399 + if ('' !== list_of_files) {
400 + list_of_files += '\n';
401 + }
402 + list_of_files += file_url;
403 + $textarea.val(list_of_files);
363 404 }
364 405
365 406 /**
366 407 *