Version Description
- NEW: Select jQuery handler
- NEW: Select Autoptimize handler
Download this release
Release Info
Developer | cloughit |
Plugin | Async JavaScript |
Version | 1.16.08.11 |
Comparing to | |
See all releases |
Code changes from version 1.16.08.10 to 1.16.08.11
- async-javascript.php +34 -11
- readme.txt +15 -10
async-javascript.php
CHANGED
@@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
4 |
Plugin Name: Async JavaScript
|
5 |
Plugin URI: https://cloughit.com.au/product/async-javascript/
|
6 |
Description: Async JavaScript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
|
7 |
-
Version: 1.16.08.
|
8 |
Author: Clough I.T. Solutions
|
9 |
Author URI: http://www.cloughit.com.au/
|
10 |
Text Domain: async-javascript
|
@@ -23,7 +23,7 @@ add_action( 'admin_init', 'aj_admin_init' );
|
|
23 |
function aj_admin_init() {
|
24 |
define( 'AJ_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
25 |
define( 'AJ_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
26 |
-
define( 'AJ_VERSION', '1.16.
|
27 |
wp_register_style(
|
28 |
'aj_admin_styles',
|
29 |
plugins_url( '/css/admin.css', __FILE__ )
|
@@ -38,17 +38,14 @@ function aj_admin_init() {
|
|
38 |
wp_localize_script( 'aj_admin_scripts', 'aj', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
|
39 |
register_setting( 'aj_options', 'aj_enabled' );
|
40 |
register_setting( 'aj_options', 'aj_method' );
|
|
|
41 |
register_setting( 'aj_options', 'aj_exclusions' );
|
42 |
register_setting( 'aj_options', 'aj_upgrade_notice' );
|
43 |
register_setting( 'aj_options', 'autoptimize_enabled' );
|
44 |
register_setting( 'aj_options', 'aj_autoptimize_enabled' );
|
|
|
45 |
$autoptimize_enabled = get_option( 'autoptimize_enabled' );
|
46 |
$aj_autoptimize_enabled = get_option( 'aj_autoptimize_enabled' );
|
47 |
-
if ( $autoptimize_enabled !== false && $aj_autoptimize_enabled === false ) {
|
48 |
-
$aj_autoptimize_enabled = $autoptimize_enabled;
|
49 |
-
update_option( 'aj_autoptimize_enabled', $aj_autoptimize_enabled );
|
50 |
-
delete_option( 'autoptimize_enabled' );
|
51 |
-
}
|
52 |
}
|
53 |
/**
|
54 |
* async_javascript_menu()
|
@@ -89,8 +86,10 @@ function async_javascript_admin() {
|
|
89 |
do_settings_sections( 'aj_options' );
|
90 |
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? array( true, 'checked', '' ) : array( false, '', 'style="display:none;"' );
|
91 |
$aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
|
|
|
92 |
$aj_exclusions = get_option( 'aj_exclusions' );
|
93 |
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? 'checked' : '';
|
|
|
94 |
?>
|
95 |
<table class="form-table" width="100%" cellpadding="10">
|
96 |
<tbody>
|
@@ -128,10 +127,20 @@ function async_javascript_admin() {
|
|
128 |
</tr>
|
129 |
</tbody>
|
130 |
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
<table class="form-table" width="100%" cellpadding="10">
|
132 |
<tbody>
|
133 |
<tr><td scope="row" align="left" colspan="2"><hr/><h3>Script Exclusion</h3></td></tr>
|
134 |
-
<tr><td scope="row" align="left" colspan="2"
|
135 |
<tr>
|
136 |
<td scope="row" align="left" style="width:20%;">Exclusions</td>
|
137 |
<td scope="row" align="left"><textarea name="aj_exclusions" style="width:95%;"><?php echo $aj_exclusions; ?></textarea></td>
|
@@ -141,16 +150,20 @@ function async_javascript_admin() {
|
|
141 |
<table class="form-table aj_method" width="100%" cellpadding="10">
|
142 |
<tbody>
|
143 |
<tr><td scope="row" align="left" colspan="2"><hr/><h3>Async JavaScript For Plugins</h3></td></tr>
|
144 |
-
<tr><td scope="row" align="left" colspan="2"><
|
145 |
<?php
|
146 |
$plugins = false;
|
147 |
-
if (is_plugin_active('autoptimize/autoptimize.php')) {
|
148 |
?>
|
149 |
<tr><td scope="row" align="left" colspan="2"><hr/><h4>Autoptimize - <a href="https://wordpress.org/plugins/autoptimize/" target="_blank"><?php echo 'https://wordpress.org/plugins/autoptimize/'; ?></a></h4></td></tr>
|
150 |
<tr>
|
151 |
<td scope="row" align="left" style="width:20%;"><label>Enable Autoptimize Support</label></td>
|
152 |
<td scope="row" align="left"><input type="checkbox" name="aj_autoptimize_enabled" value="1" <?php echo $aj_autoptimize_enabled; ?> /></td>
|
153 |
</tr>
|
|
|
|
|
|
|
|
|
154 |
<?php
|
155 |
$plugins = true;
|
156 |
}
|
@@ -191,6 +204,7 @@ add_filter( 'script_loader_tag', 'async_js', 10, 3 );
|
|
191 |
function async_js( $tag, $handle, $src ) {
|
192 |
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
|
193 |
$aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
|
|
|
194 |
$aj_exclusions = get_option( 'aj_exclusions' );
|
195 |
$array_exclusions = !empty( $aj_exclusions ) ? explode( ',', $aj_exclusions ) : array();
|
196 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
@@ -204,6 +218,14 @@ function async_js( $tag, $handle, $src ) {
|
|
204 |
}
|
205 |
}
|
206 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
$tag = str_replace( 'src=', $aj_method . "='" . $aj_method . "' src=", $tag );
|
208 |
return $tag;
|
209 |
}
|
@@ -223,9 +245,10 @@ function my_autoptimize_defer( $defer ) {
|
|
223 |
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
|
224 |
$aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
|
225 |
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? true : false;
|
|
|
226 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
227 |
if ( false !== $aj_autoptimize_enabled ) {
|
228 |
-
return " " . $
|
229 |
}
|
230 |
}
|
231 |
}
|
4 |
Plugin Name: Async JavaScript
|
5 |
Plugin URI: https://cloughit.com.au/product/async-javascript/
|
6 |
Description: Async JavaScript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
|
7 |
+
Version: 1.16.08.11
|
8 |
Author: Clough I.T. Solutions
|
9 |
Author URI: http://www.cloughit.com.au/
|
10 |
Text Domain: async-javascript
|
23 |
function aj_admin_init() {
|
24 |
define( 'AJ_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
25 |
define( 'AJ_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
26 |
+
define( 'AJ_VERSION', '1.16.08.11' );
|
27 |
wp_register_style(
|
28 |
'aj_admin_styles',
|
29 |
plugins_url( '/css/admin.css', __FILE__ )
|
38 |
wp_localize_script( 'aj_admin_scripts', 'aj', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
|
39 |
register_setting( 'aj_options', 'aj_enabled' );
|
40 |
register_setting( 'aj_options', 'aj_method' );
|
41 |
+
register_setting( 'aj_options', 'aj_jquery' );
|
42 |
register_setting( 'aj_options', 'aj_exclusions' );
|
43 |
register_setting( 'aj_options', 'aj_upgrade_notice' );
|
44 |
register_setting( 'aj_options', 'autoptimize_enabled' );
|
45 |
register_setting( 'aj_options', 'aj_autoptimize_enabled' );
|
46 |
+
register_setting( 'aj_options', 'aj_autoptimize_method' );
|
47 |
$autoptimize_enabled = get_option( 'autoptimize_enabled' );
|
48 |
$aj_autoptimize_enabled = get_option( 'aj_autoptimize_enabled' );
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
/**
|
51 |
* async_javascript_menu()
|
86 |
do_settings_sections( 'aj_options' );
|
87 |
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? array( true, 'checked', '' ) : array( false, '', 'style="display:none;"' );
|
88 |
$aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
|
89 |
+
$aj_jquery = ( get_option( 'aj_jquery' ) ) ? get_option( 'aj_jquery' ) : 'same';
|
90 |
$aj_exclusions = get_option( 'aj_exclusions' );
|
91 |
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? 'checked' : '';
|
92 |
+
$aj_autoptimize_method = ( get_option( 'aj_autoptimize_method' ) != 'async' ) ? 'defer' : 'async';
|
93 |
?>
|
94 |
<table class="form-table" width="100%" cellpadding="10">
|
95 |
<tbody>
|
127 |
</tr>
|
128 |
</tbody>
|
129 |
</table>
|
130 |
+
<table class="form-table" width="100%" cellpadding="10">
|
131 |
+
<tbody>
|
132 |
+
<tr><td scope="row" align="left" colspan="2"><hr/><h3>jQuery Handler</h3></td></tr>
|
133 |
+
<tr><td scope="row" align="left" colspan="2">If after enabling Async JavaScript for 'async' or 'defer' you receive jQuery errors in the console, try the following settings:</td></tr>
|
134 |
+
<tr>
|
135 |
+
<td scope="row" align="left" style="width:20%;">Method</td>
|
136 |
+
<td scope="row" align="left"><input type="radio" name="aj_jquery" value="same" <?php if ( $aj_jquery == 'same' ) { echo 'checked'; } ?> /> As Per Selected Method <input type="radio" name="aj_jquery" value="defer" <?php if ($aj_jquery == 'defer') { echo 'checked'; } ?> /> Defer <input type="radio" name="aj_jquery" value="async" <?php if ($aj_jquery == 'async') { echo 'checked'; } ?> /> Async <input type="radio" name="aj_jquery" value="exclude" <?php if ($aj_jquery == 'exclude') { echo 'checked'; } ?> /> Exclude </td>
|
137 |
+
</tr>
|
138 |
+
</tbody>
|
139 |
+
</table>
|
140 |
<table class="form-table" width="100%" cellpadding="10">
|
141 |
<tbody>
|
142 |
<tr><td scope="row" align="left" colspan="2"><hr/><h3>Script Exclusion</h3></td></tr>
|
143 |
+
<tr><td scope="row" align="left" colspan="2">Please list any scripts which you would like excluded from being Async/Defered during page load. (comma seperated list eg: jquery.js,jquery-ui.js)</td></tr>
|
144 |
<tr>
|
145 |
<td scope="row" align="left" style="width:20%;">Exclusions</td>
|
146 |
<td scope="row" align="left"><textarea name="aj_exclusions" style="width:95%;"><?php echo $aj_exclusions; ?></textarea></td>
|
150 |
<table class="form-table aj_method" width="100%" cellpadding="10">
|
151 |
<tbody>
|
152 |
<tr><td scope="row" align="left" colspan="2"><hr/><h3>Async JavaScript For Plugins</h3></td></tr>
|
153 |
+
<tr><td scope="row" align="left" colspan="2"><strong>Note: </strong>This will attempt to add the 'async' or 'defer' attribute to scripts loaded via a plugin (ie, not via 'wp_enqueue_script'). If you have a plugin that you would like added to this list please lodge a ticket at <a href="https://cloughit.com.au/support/?wpsc_category=8">https://cloughit.com.au/support/</a></td></tr>
|
154 |
<?php
|
155 |
$plugins = false;
|
156 |
+
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
|
157 |
?>
|
158 |
<tr><td scope="row" align="left" colspan="2"><hr/><h4>Autoptimize - <a href="https://wordpress.org/plugins/autoptimize/" target="_blank"><?php echo 'https://wordpress.org/plugins/autoptimize/'; ?></a></h4></td></tr>
|
159 |
<tr>
|
160 |
<td scope="row" align="left" style="width:20%;"><label>Enable Autoptimize Support</label></td>
|
161 |
<td scope="row" align="left"><input type="checkbox" name="aj_autoptimize_enabled" value="1" <?php echo $aj_autoptimize_enabled; ?> /></td>
|
162 |
</tr>
|
163 |
+
<tr>
|
164 |
+
<td scope="row" align="left" style="width:20%;">Method</td>
|
165 |
+
<td scope="row" align="left"><input type="radio" name="aj_autoptimize_method" value="async" <?php if ( $aj_autoptimize_method == 'async' ) { echo 'checked'; } ?> /> Async <input type="radio" name="aj_autoptimize_method" value="defer" <?php if ( $aj_autoptimize_method == 'defer' ) { echo 'checked'; } ?> /> Defer </td>
|
166 |
+
</tr>
|
167 |
<?php
|
168 |
$plugins = true;
|
169 |
}
|
204 |
function async_js( $tag, $handle, $src ) {
|
205 |
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
|
206 |
$aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
|
207 |
+
$aj_jquery = ( get_option( 'aj_jquery' ) ) ? get_option( 'aj_jquery' ) : 'same';
|
208 |
$aj_exclusions = get_option( 'aj_exclusions' );
|
209 |
$array_exclusions = !empty( $aj_exclusions ) ? explode( ',', $aj_exclusions ) : array();
|
210 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
218 |
}
|
219 |
}
|
220 |
}
|
221 |
+
if ( false !== strpos( strtolower( $src ), 'jquery.js' ) ) {
|
222 |
+
if ( $aj_jquery == 'async' || $aj_qjuery == 'defer' ) {
|
223 |
+
$tag = str_replace( 'src=', $aj_jquery . "='" . $aj_jquery . "' src=", $tag );
|
224 |
+
return $tag;
|
225 |
+
} else if ( $aj_jquery == 'exclude' ) {
|
226 |
+
return $tag;
|
227 |
+
}
|
228 |
+
}
|
229 |
$tag = str_replace( 'src=', $aj_method . "='" . $aj_method . "' src=", $tag );
|
230 |
return $tag;
|
231 |
}
|
245 |
$aj_enabled = ( get_option( 'aj_enabled' ) == 1 ) ? true : false;
|
246 |
$aj_method = ( get_option( 'aj_method' ) != 'async' ) ? 'defer' : 'async';
|
247 |
$aj_autoptimize_enabled = ( get_option( 'aj_autoptimize_enabled' ) == 1 ) ? true : false;
|
248 |
+
$aj_autoptimize_method = ( get_option( 'aj_autoptimize_method' ) != 'async' ) ? 'defer' : 'async';
|
249 |
if ( false !== $aj_enabled && false === is_admin() ) {
|
250 |
if ( false !== $aj_autoptimize_enabled ) {
|
251 |
+
return " " . $aj_autoptimize_method . "='" . $aj_autoptimize_method . "' ";
|
252 |
}
|
253 |
}
|
254 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.cloughit.com.au/donate/ (coming soon)
|
|
4 |
Tags: async,javascript,google,pagespeed,js,speed,performance,boost,render,blocking,above-the-fold
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 4.6
|
7 |
-
Stable tag: 1.16.08.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,18 +12,18 @@ Async JavaScript adds a 'async' attribute to scripts loaded via wp_enqueue_scrip
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
|
16 |
|
17 |
-
Render-blocking JavaScript prevents above-the-fold content on your page from being rendered until the
|
18 |
|
19 |
-
Async JavaScript adds a 'async' or 'defer' attribute to all
|
20 |
|
21 |
-
<em>
|
22 |
|
23 |
-
* Selective 'async'
|
24 |
-
* Selective 'defer'
|
25 |
-
* Exclude individual scripts
|
26 |
-
* Exclude plugins
|
27 |
|
28 |
<a href="http://cloughit.com.au/product/async-javascript-pro/" target="_blank">Read more...</a>
|
29 |
|
@@ -49,7 +49,7 @@ The 'async' attribute is new in HTML5. It is supported by the following browsers
|
|
49 |
|
50 |
= Where can I report an error? =
|
51 |
|
52 |
-
Please lodge a support request at https://
|
53 |
|
54 |
= What information should I include when requesting support =
|
55 |
|
@@ -70,6 +70,11 @@ Please lodge a support request at https://wordpress.org/support/plugin/async-jav
|
|
70 |
|
71 |
== Changelog ==
|
72 |
|
|
|
|
|
|
|
|
|
|
|
73 |
= 1.16.08.10 =
|
74 |
|
75 |
* FIX: Return $tag instead of $src
|
4 |
Tags: async,javascript,google,pagespeed,js,speed,performance,boost,render,blocking,above-the-fold
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 4.6
|
7 |
+
Stable tag: 1.16.08.11
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
+
Help to eliminate Render-blocking JavaScript in above-the-fold content with Async JavaScript.
|
16 |
|
17 |
+
Render-blocking JavaScript prevents above-the-fold content on your page from being rendered until the JavaScript has finished loading. This can impact on your page speed and ultimately your ranking within search engines. It can also impact your users experience.
|
18 |
|
19 |
+
Async JavaScript adds a 'async' or 'defer' attribute to all JavaScripts loaded by the WordPress wp_enqueue_script function. This 'async' or 'defer' attribute forces the javascript to be loaded asynchronously or deferred, therefore speeding up page delivery.
|
20 |
|
21 |
+
<em>Want more control? </em><strong>Async JavaScript Pro</strong> allows you to:
|
22 |
|
23 |
+
* Selective 'async' - choose which JavaScripts to apply 'async' to
|
24 |
+
* Selective 'defer' - choose which JavaScripts to apply 'defer' to
|
25 |
+
* Exclude individual scripts - choose which JavaScripts to ignore
|
26 |
+
* Exclude plugins - choose local plugin JavaScripts to ignore
|
27 |
|
28 |
<a href="http://cloughit.com.au/product/async-javascript-pro/" target="_blank">Read more...</a>
|
29 |
|
49 |
|
50 |
= Where can I report an error? =
|
51 |
|
52 |
+
Please lodge a support request at <a href="https://cloughit.com.au/support/?wpsc_category=8" target="_blank">https://cloughit.com.au/support/</a>
|
53 |
|
54 |
= What information should I include when requesting support =
|
55 |
|
70 |
|
71 |
== Changelog ==
|
72 |
|
73 |
+
= 1.16.08.11 =
|
74 |
+
|
75 |
+
* NEW: Select jQuery handler
|
76 |
+
* NEW: Select Autoptimize handler
|
77 |
+
|
78 |
= 1.16.08.10 =
|
79 |
|
80 |
* FIX: Return $tag instead of $src
|