Autoptimize - Version 2.3.2

Version Description

  • workaround for stale options-data in external object cache such as Redis, Memcached (core bug) resulting in Autoptimize continuously executing the upgrade-procedure including clearing the cache and trying to preload it with HTTP-requests with "cachebuster" in the query string, thanks to Haroon Q. Raja and Tomas Trkulja for their great assistance!
  • fixes for "undefined index" notices on Extra settings page
  • now removing respective dns-prefetch resource hints when "remove emojis" or when Google Fonts are optimized or removed.
  • changed JS code to load webfont.js deferred instead of asynced to make sure the js-file or fonts are not consider render blocking.
Download this release

Release Info

Developer futtta
Plugin Icon 128x128 Autoptimize
Version 2.3.2
Comparing to
See all releases

Code changes from version 2.3.1 to 2.3.2

autoptimize.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Autoptimize
4
  Plugin URI: https://autoptimize.com/
5
  Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6
- Version: 2.3.1
7
  Author: Frank Goossens (futtta)
8
  Author URI: https://autoptimize.com/
9
  Domain Path: localization/
3
  Plugin Name: Autoptimize
4
  Plugin URI: https://autoptimize.com/
5
  Description: Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.
6
+ Version: 2.3.2
7
  Author: Frank Goossens (futtta)
8
  Author URI: https://autoptimize.com/
9
  Domain Path: localization/
classlesses/autoptimizeExtra.php CHANGED
@@ -24,12 +24,12 @@ function autoptimize_extra_init() {
24
  $autoptimize_extra_options = autoptimize_extra_get_options();
25
 
26
  /* disable emojis */
27
- if ($autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) {
28
  autoptimize_extra_disable_emojis();
29
  }
30
 
31
  /* remove version from query string */
32
- if ($autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) {
33
  add_filter( 'script_loader_src', 'autoptimize_extra_remove_qs', 15, 1 );
34
  add_filter( 'style_loader_src', 'autoptimize_extra_remove_qs', 15, 1 );
35
  }
@@ -41,6 +41,7 @@ function autoptimize_extra_init() {
41
 
42
  /* optimize google fonts */
43
  if ( !empty( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] ) && ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1" ) ) {
 
44
  if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2" ) {
45
  add_filter('autoptimize_filter_css_removables','autoptimize_extra_remove_gfonts',10,1);
46
  } else {
@@ -68,6 +69,9 @@ function autoptimize_extra_disable_emojis() {
68
 
69
  // filter to remove TinyMCE emojis
70
  add_filter( 'tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce' );
 
 
 
71
  }
72
 
73
  function autoptimize_extra_disable_emojis_tinymce( $plugins ) {
@@ -78,6 +82,12 @@ function autoptimize_extra_disable_emojis_tinymce( $plugins ) {
78
  }
79
  }
80
 
 
 
 
 
 
 
81
  // remove query string function
82
  function autoptimize_extra_remove_qs( $src ) {
83
  if ( strpos($src, '?ver=') ) {
@@ -147,6 +157,12 @@ function autoptimize_extra_preconnect($hints, $relation_type) {
147
  }
148
 
149
  // google font functions
 
 
 
 
 
 
150
  function autoptimize_extra_remove_gfonts($in) {
151
  // simply remove google fonts
152
  return $in.", fonts.googleapis.com";
@@ -229,7 +245,7 @@ function autoptimize_extra_gfonts($in) {
229
  $_fontsOut .= $_font."','";
230
  }
231
  $_fontsOut = trim(trim($_fontsOut,"'"),",");
232
- $_fontsOut .= '] },classes:false, events:false, timeout:1500};(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
233
  }
234
 
235
  // inject in HTML
@@ -244,12 +260,26 @@ function autoptimize_extra_preconnectgooglefonts($in) {
244
  $in[] = "https://fonts.gstatic.com";
245
  if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) {
246
  // and more preconnects for webfont.js
247
- $in[] = "https://ajax.googleapis.com/";
248
  $in[] = "https://fonts.googleapis.com";
249
  }
250
  return $in;
251
  }
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  /* admin page functions */
254
  function autoptimize_extra_admin() {
255
  add_submenu_page( null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page' );
@@ -281,13 +311,13 @@ function autoptimize_extra_options_page() {
281
  <tr>
282
  <th scope="row"><?php _e('Remove emojis','autoptimize'); ?></th>
283
  <td>
284
- <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php checked( $autoptimize_extra_options['autoptimize_extra_checkbox_field_1'], 1 ); ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.','autoptimize'); ?></label>
285
  </td>
286
  </tr>
287
  <tr>
288
  <th scope="row"><?php _e('Remove query strings from static resources','autoptimize'); ?></th>
289
  <td>
290
- <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php checked( $autoptimize_extra_options['autoptimize_extra_checkbox_field_0'], 1 ); ?> value='1'><?php _e('Removing query strings (or more specificaly the <code>ver</code> parameter) will not improve load time, but might improve performance scores.','autoptimize'); ?></label>
291
  </td>
292
  </tr>
293
  <tr>
24
  $autoptimize_extra_options = autoptimize_extra_get_options();
25
 
26
  /* disable emojis */
27
+ if ( !empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) ) {
28
  autoptimize_extra_disable_emojis();
29
  }
30
 
31
  /* remove version from query string */
32
+ if ( !empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) ) {
33
  add_filter( 'script_loader_src', 'autoptimize_extra_remove_qs', 15, 1 );
34
  add_filter( 'style_loader_src', 'autoptimize_extra_remove_qs', 15, 1 );
35
  }
41
 
42
  /* optimize google fonts */
43
  if ( !empty( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] ) && ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] != "1" ) ) {
44
+ add_filter( 'wp_resource_hints', 'autoptimize_extra_gfonts_remove_dnsprefetch', 10, 2 );
45
  if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "2" ) {
46
  add_filter('autoptimize_filter_css_removables','autoptimize_extra_remove_gfonts',10,1);
47
  } else {
69
 
70
  // filter to remove TinyMCE emojis
71
  add_filter( 'tiny_mce_plugins', 'autoptimize_extra_disable_emojis_tinymce' );
72
+
73
+ // and remove dns-prefetch for emoji
74
+ add_filter( 'wp_resource_hints', 'autoptimize_extra_emojis_remove_dns_prefetch', 10, 2 );
75
  }
76
 
77
  function autoptimize_extra_disable_emojis_tinymce( $plugins ) {
82
  }
83
  }
84
 
85
+ function autoptimize_extra_emojis_remove_dns_prefetch( $urls, $relation_type ) {
86
+ $_emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' );
87
+
88
+ return autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_emoji_svg_url );
89
+ }
90
+
91
  // remove query string function
92
  function autoptimize_extra_remove_qs( $src ) {
93
  if ( strpos($src, '?ver=') ) {
157
  }
158
 
159
  // google font functions
160
+ function autoptimize_extra_gfonts_remove_dnsprefetch ( $urls, $relation_type ) {
161
+ $_gfonts_url = "fonts.googleapis.com";
162
+
163
+ return autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_gfonts_url );
164
+ }
165
+
166
  function autoptimize_extra_remove_gfonts($in) {
167
  // simply remove google fonts
168
  return $in.", fonts.googleapis.com";
245
  $_fontsOut .= $_font."','";
246
  }
247
  $_fontsOut = trim(trim($_fontsOut,"'"),",");
248
+ $_fontsOut .= '] },classes:false, events:false, timeout:1500};(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.defer=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>';
249
  }
250
 
251
  // inject in HTML
260
  $in[] = "https://fonts.gstatic.com";
261
  if ( $autoptimize_extra_options['autoptimize_extra_radio_field_4'] == "4" ) {
262
  // and more preconnects for webfont.js
263
+ $in[] = "https://ajax.googleapis.com";
264
  $in[] = "https://fonts.googleapis.com";
265
  }
266
  return $in;
267
  }
268
 
269
+ function autoptimize_extra_remove_dns_prefetch( $urls, $relation_type, $_remove_url ) {
270
+ if ( 'dns-prefetch' == $relation_type ) {
271
+ $_count=0;
272
+ foreach ($urls as $_url) {
273
+ if ( strpos($_url, $_remove_url) !== false ) {
274
+ unset($urls[$_count]);
275
+ }
276
+ $_count++;
277
+ }
278
+ }
279
+
280
+ return $urls;
281
+ }
282
+
283
  /* admin page functions */
284
  function autoptimize_extra_admin() {
285
  add_submenu_page( null, 'autoptimize_extra', 'autoptimize_extra', 'manage_options', 'autoptimize_extra', 'autoptimize_extra_options_page' );
311
  <tr>
312
  <th scope="row"><?php _e('Remove emojis','autoptimize'); ?></th>
313
  <td>
314
+ <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) && 1 == $autoptimize_extra_options['autoptimize_extra_checkbox_field_1']) echo 'checked="checked"'; ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.','autoptimize'); ?></label>
315
  </td>
316
  </tr>
317
  <tr>
318
  <th scope="row"><?php _e('Remove query strings from static resources','autoptimize'); ?></th>
319
  <td>
320
+ <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty( $autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) && 1 == $autoptimize_extra_options['autoptimize_extra_checkbox_field_0']) echo 'checked="checked"'; ?> value='1'><?php _e('Removing query strings (or more specificaly the <code>ver</code> parameter) will not improve load time, but might improve performance scores.','autoptimize'); ?></label>
321
  </td>
322
  </tr>
323
  <tr>
classlesses/autoptimizeUpdateCode.php CHANGED
@@ -98,8 +98,9 @@ switch($autoptimize_major_version) {
98
  $majorUp = true;
99
  }
100
 
101
- if ( $majorUp === true ) {
102
  // clear cache and notify user to check result if major upgrade
 
103
  autoptimizeCache::clearall();
104
  add_action('admin_notices', 'autoptimize_update_config_notice');
105
  }
98
  $majorUp = true;
99
  }
100
 
101
+ if ( $majorUp === true && get_transient('autoptimize_stale_option_buster') == false ) {
102
  // clear cache and notify user to check result if major upgrade
103
+ set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS);
104
  autoptimizeCache::clearall();
105
  add_action('admin_notices', 'autoptimize_update_config_notice');
106
  }
readme.txt CHANGED
@@ -1,16 +1,16 @@
1
  === Autoptimize ===
2
  Contributors: futtta, optimizingmatters, turl
3
- Tags: css, javascript, optimize, minify, performance
4
  Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
- Stable tag: 2.3.1
8
 
9
- Autoptimize speeds up your website and helps you save bandwidth by aggregating and minimizing JS, CSS and HTML.
10
 
11
  == Description ==
12
 
13
- Autoptimize makes optimizing your site really easy. It can aggregate, minify and cache scripts and styles, injects CSS in the page head by default and can move and defer scripts to the footer. It also minifies the HTML code itself, making your page really lightweight. There are advanced options and an extensive API available to enable you to tailor Autoptimize to each and every site's specific needs. And it can even improve your site's performance when on HTTP/2!
14
 
15
  If you consider performance important, you really should use one of the many caching plugins to do page caching. Some good candidates to complement Autoptimize that way are e.g. [WP Super Cache](http://wordpress.org/plugins/wp-super-cache/), [HyperCache](http://wordpress.org/plugins/hyper-cache/), [Comet Cache](https://wordpress.org/plugins/comet-cache/) or [KeyCDN's Cache Enabler](https://wordpress.org/plugins/cache-enabler).
16
 
@@ -196,7 +196,8 @@ NextGen Galleries does some nifty stuff to add JavaScript. In order for Autoptim
196
  = What is noptimize? =
197
 
198
  Starting with version 1.6.6 Autoptimize excludes everything inside noptimize tags, e.g.:
199
- `&lt;!--noptimize-->&lt;script>alert('this will not get autoptimized');&lt;/script>&lt;!--/noptimize-->`
 
200
 
201
  You can do this in your page/ post content, in widgets and in your theme files (consider creating [a child theme](http://codex.wordpress.org/Child_Themes) to avoid your work being overwritten by theme updates).
202
 
@@ -248,6 +249,12 @@ Just [fork Autoptimize on Github](https://github.com/futtta/autoptimize) and cod
248
 
249
  == Changelog ==
250
 
 
 
 
 
 
 
251
  = 2.3.1 =
252
  * fix for issue with update-code in some circumstances, thanks to [Rajendra Zore](https://rajendrazore.com/) to report & help fix!
253
 
1
  === Autoptimize ===
2
  Contributors: futtta, optimizingmatters, turl
3
+ Tags: optimize, minify, performance, pagespeed, async
4
  Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
5
  Requires at least: 4.0
6
  Tested up to: 4.9
7
+ Stable tag: 2.3.2
8
 
9
+ Autoptimize speeds up your website by optimizing JS, CSS and HTML, async-ing JavaScript, removing emoji cruft, optimizing Google Fonts and more.
10
 
11
  == Description ==
12
 
13
+ Autoptimize makes optimizing your site really easy. It can aggregate, minify and cache scripts and styles, injects CSS in the page head by default (but can also defer), moves and defers scripts to the footer and minifies HTML. The "Extra" options allow you to async non-aggregated JavaScript, remove WordPress core emoji cruft, optimize Google Fonts and more. As such it can improve your site's performance even when already on HTTP/2! There is extensive API available to enable you to tailor Autoptimize to each and every site's specific needs.
14
 
15
  If you consider performance important, you really should use one of the many caching plugins to do page caching. Some good candidates to complement Autoptimize that way are e.g. [WP Super Cache](http://wordpress.org/plugins/wp-super-cache/), [HyperCache](http://wordpress.org/plugins/hyper-cache/), [Comet Cache](https://wordpress.org/plugins/comet-cache/) or [KeyCDN's Cache Enabler](https://wordpress.org/plugins/cache-enabler).
16
 
196
  = What is noptimize? =
197
 
198
  Starting with version 1.6.6 Autoptimize excludes everything inside noptimize tags, e.g.:
199
+
200
+ <!--noptimize--><script>alert('this will not get autoptimized')></script><!--/noptimize-->
201
 
202
  You can do this in your page/ post content, in widgets and in your theme files (consider creating [a child theme](http://codex.wordpress.org/Child_Themes) to avoid your work being overwritten by theme updates).
203
 
249
 
250
  == Changelog ==
251
 
252
+ = 2.3.2 =
253
+ * workaround for [stale options-data in external object cache such as Redis, Memcached (core bug)](https://core.trac.wordpress.org/ticket/31245) resulting in Autoptimize continuously executing the upgrade-procedure including clearing the cache and trying to preload it with HTTP-requests with "cachebuster" in the query string, thanks to [Haroon Q. Raja](https://hqraja.com/) and [Tomas Trkulja](https://twitter.com/zytzagoo) for their great assistance!
254
+ * fixes for "undefined index" notices on Extra settings page
255
+ * now removing respective dns-prefetch resource hints when "remove emojis" or when Google Fonts are optimized or removed.
256
+ * changed JS code to load webfont.js deferred instead of asynced to make sure the js-file or fonts are not consider render blocking.
257
+
258
  = 2.3.1 =
259
  * fix for issue with update-code in some circumstances, thanks to [Rajendra Zore](https://rajendrazore.com/) to report & help fix!
260