Page Optimize - Version 0.5.0

Version Description

  • Apply the script_loader_tag filter for scripts that are concatenate-able but have no neighbors to concatenate with. This fixes a case where the TwentyTwenty theme wanted to apply a defer attribute to its script but was never given the opportunity.
Download this release

Release Info

Developer bpayton
Plugin Icon wp plugin Page Optimize
Version 0.5.0
Comparing to
See all releases

Code changes from version 0.4.7 to 0.5.0

Files changed (3) hide show
  1. concat-js.php +12 -2
  2. page-optimize.php +1 -1
  3. readme.txt +4 -1
concat-js.php CHANGED
@@ -249,10 +249,20 @@ class Page_Optimize_JS_Concat extends WP_Scripts {
249
  $load_mode = page_optimize_load_mode_js();
250
 
251
  if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
252
- echo "<script data-handles='" . esc_attr( $handles ) . "' $load_mode type='text/javascript' src='$href'></script>\n";
253
  } else {
254
- echo "<script type='text/javascript' $load_mode src='$href'></script>\n";
255
  }
 
 
 
 
 
 
 
 
 
 
256
  }
257
 
258
  if ( isset( $js_array['extras']['after'] ) ) {
249
  $load_mode = page_optimize_load_mode_js();
250
 
251
  if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
252
+ $tag = "<script data-handles='" . esc_attr( $handles ) . "' $load_mode type='text/javascript' src='$href'></script>\n";
253
  } else {
254
+ $tag = "<script type='text/javascript' $load_mode src='$href'></script>\n";
255
  }
256
+
257
+ if ( is_array( $js_array['handles'] ) && count( $js_array['handles'] ) === 1 ) {
258
+ // Because we have a single script, let's apply the `script_loader_tag` filter as core does in `do_item()`.
259
+ // That way, we interfere less with plugin and theme script filtering. For example, without this filter,
260
+ // there is a case where we block the TwentyTwenty theme from adding async/defer attributes.
261
+ // https://github.com/Automattic/page-optimize/pull/44
262
+ $tag = apply_filters( 'script_loader_tag', $tag, $js_array['handles'][0], $href );
263
+ }
264
+
265
+ echo $tag;
266
  }
267
 
268
  if ( isset( $js_array['extras']['after'] ) ) {
page-optimize.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Page Optimize
4
  Plugin URI: https://wordpress.org/plugins/page-optimize/
5
  Description: Optimizes JS and CSS for faster page load and render in the browser.
6
  Author: Automattic
7
- Version: 0.4.7
8
  Author URI: http://automattic.com/
9
  */
10
 
4
  Plugin URI: https://wordpress.org/plugins/page-optimize/
5
  Description: Optimizes JS and CSS for faster page load and render in the browser.
6
  Author: Automattic
7
+ Version: 0.5.0
8
  Author URI: http://automattic.com/
9
  */
10
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: performance
4
  Requires at least: 5.3
5
  Tested up to: 5.4
6
  Requires PHP: 7.0
7
- Stable tag: 0.4.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -49,6 +49,9 @@ Supported query params:
49
 
50
  == Changelog ==
51
 
 
 
 
52
  = 0.4.5, 0.4.6 =
53
  * Force absolute paths for CSS replacements.
54
  * Lower required PHP version to 7.0.
4
  Requires at least: 5.3
5
  Tested up to: 5.4
6
  Requires PHP: 7.0
7
+ Stable tag: 0.5.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
49
 
50
  == Changelog ==
51
 
52
+ = 0.5.0 =
53
+ * Apply the `script_loader_tag` filter for scripts that are concatenate-able but have no neighbors to concatenate with. This fixes a case where the TwentyTwenty theme wanted to apply a `defer` attribute to its script but was never given the opportunity.
54
+
55
  = 0.4.5, 0.4.6 =
56
  * Force absolute paths for CSS replacements.
57
  * Lower required PHP version to 7.0.