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/cache.js +119 -51 3.3.1 → 4.7.0 View file →
@@ -1,7 +1,8 @@
1 1 var WP_Optimize_Cache = function () {
2 2
3 3 var $ = jQuery;
4 + var block_ui = wp_optimize.block_ui;
4 5 var send_command = wp_optimize.send_command;
5 6 var heartbeat = WP_Optimize_Heartbeat();
6 7 var heartbeat_agents = [];
7 8
@@ -13,15 +14,19 @@
13 14 /**
14 15 * Handle purge cache btn.
15 16 */
16 17 purge_cache_btn.on('click', function() {
18 +
17 19 var btn = $(this),
18 20 spinner = btn.next(),
19 21 success_icon = spinner.next();
20 22
23 + if (btn.prop('disabled')) return false;
24 + btn.prop('disabled', true);
21 25 spinner.show();
22 26
23 27 send_command('purge_page_cache', {}, function(response) {
28 + btn.prop('disabled', false);
24 29 spinner.hide();
25 30 success_icon.show();
26 31 setTimeout(function() {
27 32 success_icon.fadeOut('slow', function() {
@@ -63,9 +68,9 @@
63 68
64 69 /**
65 70 * Handle Enable Gzip compression button click.
66 71 */
67 - $('#wp_optimize_gzip_compression_enable').on('click', function() {
72 + $('#wp-optimize-nav-tab-wpo_cache-gzip-contents').on('click', '#wp_optimize_gzip_compression_enable', function() {
68 73 var button = $(this),
69 74 loader = button.next();
70 75
71 76 loader.show();
@@ -70,20 +75,13 @@
70 75
71 76 loader.show();
72 77
73 78 send_command('enable_gzip_compression', {enable: button.data('enable')}, function(response) {
74 - var gzip_status_message = $('#wpo_gzip_compression_status');
75 79 if (response) {
76 - if (response.enabled) {
77 - button.text(wpoptimize.disable);
78 - button.data('enable', '0');
79 - gzip_status_message.removeClass('wpo-disabled').addClass('wpo-enabled');
80 - } else {
81 - button.text(wpoptimize.enable);
82 - button.data('enable', '1');
83 - gzip_status_message.addClass('wpo-disabled').removeClass('wpo-enabled');
84 - }
85 80
81 + $('#wpo_gzip_compression_test_btn').trigger('click');
82 +
83 + // Handle error message
86 84 if (response.message) {
87 85 $('#wpo_gzip_compression_error_message').text(response.message).show();
88 86 } else {
89 87 $('#wpo_gzip_compression_error_message').hide();
@@ -106,11 +104,52 @@
106 104 });
107 105 });
108 106
109 107 /**
108 + * Handle Test again compressions button click
109 + */
110 + $('#wp-optimize-nav-tab-wpo_cache-gzip-contents').on('click', '#wpo_gzip_compression_test_btn', function() {
111 + var btn = $(this);
112 +
113 + if (btn.prop('disabled')) return;
114 +
115 + btn.prop('disabled', true);
116 + $('#wpo_gzip_compression_details').hide();
117 + $('#wpo_gzip_control_panel .wpo_shade').removeClass('hidden');
118 +
119 + send_command('get_compression_test_results_html', {}, function(response) {
120 + if (response.results_html) {
121 + $('#wpo_gzip_compression_details').html(response.results_html);
122 + } else {
123 + $('#wpo_gzip_compression_details').text(wpoptimize.error_unexpected_response);
124 + }
125 +
126 + if (response.gzip_compression_control_panel) {
127 + $('#wpo_gzip_control_panel').html(response.gzip_compression_control_panel);
128 + }
129 + }).fail(function() {
130 + alert(wpoptimize.error_unexpected_response);
131 + }).always(function() {
132 + $('#wpo_gzip_control_panel .wpo_shade').addClass('hidden');
133 + $('#wpo_gzip_compression_details').show();
134 + btn.prop('disabled', false);
135 + });
136 + });
137 +
138 + /**
139 + * Update gzip test results when tab is activated
140 + */
141 + $('#wp-optimize-wrap').on('tab-change/wpo_cache/gzip', function() {
142 + if (!$('#wp-optimize-nav-tab-wpo_cache-gzip').data('activated')) {
143 + $('#wp-optimize-nav-tab-wpo_cache-gzip').data('activated', true);
144 + $('#wpo_gzip_compression_test_btn').trigger('click');
145 + }
146 + });
147 +
148 + /**
110 149 * Manually check gzip status
111 150 */
112 - $('.wpo-refresh-gzip-status').on('click', function(e) {
151 + $('#wp-optimize-nav-tab-wpo_cache-gzip-contents').on('click', '.wpo-refresh-gzip-status', function(e) {
113 152 e.preventDefault();
114 153 $link = $(this);
115 154 $link.addClass('loading');
116 155 send_command('get_gzip_compression_status', null, function(response) {
@@ -147,12 +186,12 @@
147 186 if (isNaN(browser_cache_expire_days)) browser_cache_expire_days = 0;
148 187 if (isNaN(browser_cache_expire_hours)) browser_cache_expire_hours = 0;
149 188
150 189 if (browser_cache_expire_days < 0 || browser_cache_expire_hours < 0) {
151 - $('#wpo_browser_cache_error_message').text(wpoptimize.please_use_positive_integers).show();
190 + alert(wpoptimize.please_use_positive_integers);
152 191 return false;
153 192 } else if (browser_cache_expire_hours > 23) {
154 - $('#wpo_browser_cache_error_message').text(wpoptimize.please_use_valid_values).show();
193 + alert(wpoptimize.please_use_valid_values);
155 194 return false;
156 195 } else {
157 196 $('#wpo_browser_cache_error_message').hide();
158 197 }
@@ -162,46 +201,48 @@
162 201 browser_cache_expire_hours_el.val(browser_cache_expire_hours);
163 202
164 203 loader.show();
165 204
166 - send_command('enable_browser_cache', {browser_cache_expire_days: browser_cache_expire_days, browser_cache_expire_hours: browser_cache_expire_hours}, function(response) {
167 - var cache_status_message = $('#wpo_browser_cache_status');
168 - var cache_status_field = $('#wpo_enable_browser_cache');
169 - if (response) {
170 - if (response.enabled) {
171 - button.text(wpoptimize.update);
172 - cache_status_message.removeClass('wpo-disabled').addClass('wpo-enabled');
173 - cache_status_field.val('true');
174 - } else {
175 - button.text(wpoptimize.enable);
176 - cache_status_message.addClass('wpo-disabled').removeClass('wpo-enabled');
177 - cache_status_field.val('false');
178 - }
205 + send_command('enable_browser_cache',
206 + {browser_cache_expire_days: browser_cache_expire_days,
207 + browser_cache_expire_hours: browser_cache_expire_hours}, function(response) {
208 + var cache_status_message = $('#wpo_browser_cache_status');
209 + var cache_status_field = $('#wpo_enable_browser_cache');
210 + if (response) {
211 + if (response.enabled) {
212 + button.text(wpoptimize.update);
213 + cache_status_message.removeClass('wpo-disabled').addClass('wpo-enabled');
214 + cache_status_field.val('true');
215 + } else {
216 + button.text(wpoptimize.enable);
217 + cache_status_message.addClass('wpo-disabled').removeClass('wpo-enabled');
218 + cache_status_field.val('false');
219 + }
179 220
180 - if (response.message) {
181 - $('#wpo_browser_cache_message').text(response.message).show();
182 - } else {
183 - $('#wpo_browser_cache_message').hide();
184 - }
221 + if (response.message) {
222 + $('#wpo_browser_cache_message').text(response.message).show();
223 + } else {
224 + $('#wpo_browser_cache_message').hide();
225 + }
185 226
186 - if (response.error_message) {
187 - $('#wpo_browser_cache_error_message').text(response.error_message).show();
188 - } else {
189 - $('#wpo_browser_cache_error_message').hide();
190 - }
227 + if (response.error_message) {
228 + $('#wpo_browser_cache_error_message').text(response.error_message).show();
229 + } else {
230 + $('#wpo_browser_cache_error_message').hide();
231 + }
191 232
192 - if (response.output) {
193 - $('#wpo_browser_cache_output').html(response.output).show();
233 + if (response.output) {
234 + $('#wpo_browser_cache_output').html(response.output).show();
235 + } else {
236 + $('#wpo_browser_cache_output').hide();
237 + }
238 +
194 239 } else {
195 - $('#wpo_browser_cache_output').hide();
240 + alert(wpoptimize.error_unexpected_response);
196 241 }
197 242
198 - } else {
199 - alert(wpoptimize.error_unexpected_response);
200 - }
201 -
202 - loader.hide();
203 - }).fail(function() {
243 + loader.hide();
244 + }).fail(function() {
204 245 alert(wpoptimize.error_unexpected_response);
205 246 loader.hide();
206 247 });
207 248 });
@@ -259,9 +300,9 @@
259 300 spinner = btn.next(),
260 301 success_icon = spinner.next();
261 302
262 303 spinner.show();
263 - $.blockUI();
304 + block_ui(wpoptimize.saving);
264 305
265 306 send_command('save_cache_settings', { 'cache-settings': gather_cache_settings() }, function(response) {
266 307
267 308 if (response.hasOwnProperty('js_trigger')) {
@@ -317,8 +358,10 @@
317 358 $('#wp_optimize_run_minify_preload').prop('disabled', false);
318 359 $('#minify-preload').hide();
319 360 }
320 361
362 + $(document).trigger('wp-optimize/cache/toggle-status', {enabled: response.enabled});
363 +
321 364 if (response.result) {
322 365 // If Result is true, show the success icon.
323 366 success_icon.show();
324 367 setTimeout(function() {
@@ -387,11 +430,9 @@
387 430
388 431 if (is_running) {
389 432 btn.data('running', false);
390 433
391 - while(agent_id = heartbeat_agents.shift()) {
392 - heartbeat.cancel_agent(agent_id);
393 - }
434 + heartbeat.cancel_agents(heartbeat_agents);
394 435
395 436 send_command(
396 437 'cancel_cache_preload',
397 438 null,
@@ -463,9 +504,10 @@
463 504 */
464 505 function run_update_cache_preload_status() {
465 506 var agent = heartbeat.add_agent({
466 507 command: 'get_cache_preload_status',
467 - callback: update_cache_preload_status
508 + callback: update_cache_preload_status,
509 + _keep: false
468 510 });
469 511
470 512 if (null !== agent) heartbeat_agents.push(agent);
471 513 }
@@ -496,7 +538,33 @@
496 538 function update_cache_size_information(response) {
497 539 $('#wpo_current_cache_size_information').text(wpoptimize.current_cache_size + ' ' + response.size);
498 540 $('#wpo_current_cache_file_count').text(wpoptimize.number_of_files + ' ' + response.file_count);
499 541 }
542 +
543 +
544 + $('#wpo-auto-preload-after-purge').on('click', function() {
545 + var clicked_btn = this;
546 + var success_icon = $(this).closest('.wpo-fieldgroup__subgroup').find('.dashicons-yes');
547 +
548 + clicked_btn.disabled = true;
549 +
550 + block_ui(wpoptimize.saving);
551 +
552 + send_command(
553 + 'save_cache_auto_preload_option',
554 + { enabled: !!clicked_btn.checked },
555 + function(response) {
556 + clicked_btn.disabled = false;
557 + $.unblockUI();
558 + if (response.success) {
559 + success_icon.show().fadeOut(1000);
560 + } else {
561 + clicked_btn.checked = !clicked_btn.checked;
562 + alert(response.message);
563 + }
564 +
565 + }
566 + );
567 + });
500 568
501 569 wp_optimize.cache_settings = gather_cache_settings;
502 570 };