Async JavaScript - Version 1.16.02.15

Version Description

  • NEW: Added information for Async Javascript Pro
Download this release

Release Info

Developer cloughit
Plugin Icon 128x128 Async JavaScript
Version 1.16.02.15
Comparing to
See all releases

Code changes from version 1.15.08.21.1 to 1.16.02.15

async-javascript.php CHANGED
@@ -1,3 +1,197 @@
1
- <?php
2
  * aj_admin_init()
3
  *
4
  * register admin stylesheets and javascripts
5
  *
6
  * @param n/a
7
  * @return n/a
8
  */
9
- wp_enqueue_script(
10
- /**
11
  * async_javascript_menu()
12
  *
13
  * register admin menu
14
  *
15
  * @param n/a
16
  * @return n/a
17
  */
18
  * async_javascript_admin()
19
  *
20
  * admin page
21
  *
22
  * @param n/a
23
  * @return n/a
24
  */
25
  * async_js()
26
  *
27
  * add 'async' attribute to '<script>' tasks called via wp_enqueue_script using the 'clean_url' filter
28
  *
29
  * @param string $url url being processed
30
  * @return string $url modified url string
31
  */
32
  * my_autoptimize_defer()
33
  *
34
  * Adds support for Autoptimize plugin. Adds 'async' attribute to '<script>' tasks called via autoptimize_filter_js_defer filter
35
  * Autoptimize: https://wordpress.org/plugins/autoptimize/
36
  *
37
  * @param string $defer current value of $defer as passed to function
38
  * @return string 'async' attribute
39
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  * aj_admin_init()
2
  *
3
  * register admin stylesheets and javascripts
4
  *
5
  * @param n/a
6
  * @return n/a
7
  */
 
 
8
  * async_javascript_menu()
9
  *
10
  * register admin menu
11
  *
12
  * @param n/a
13
  * @return n/a
14
  */
15
  * async_javascript_admin()
16
  *
17
  * admin page
18
  *
19
  * @param n/a
20
  * @return n/a
21
  */
22
  * async_js()
23
  *
24
  * add 'async' attribute to '<script>' tasks called via wp_enqueue_script using the 'clean_url' filter
25
  *
26
  * @param string $url url being processed
27
  * @return string $url modified url string
28
  */
29
  * my_autoptimize_defer()
30
  *
31
  * Adds support for Autoptimize plugin. Adds 'async' attribute to '<script>' tasks called via autoptimize_filter_js_defer filter
32
  * Autoptimize: https://wordpress.org/plugins/autoptimize/
33
  *
34
  * @param string $defer current value of $defer as passed to function
35
  * @return string 'async' attribute
36
  */
37
+ <?php
38
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
39
+ /*
40
+ Plugin Name: Async Javascript
41
+ Plugin URI: http://www.cloughit.com.au/wordpress/plugins/async-javascript-wordpress-plugin/
42
+ Description: Async Javascript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
43
+ Version: 1.16.02.15
44
+ Author: David Clough (cloughit)
45
+ Author URI: http://www.cloughit.com.au/
46
+ Text Domain: async-javascript
47
+ License: GNU General Public License v2 or later
48
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
49
+ */
50
+ /**
51
+ * aj_admin_init()
52
+ *
53
+ * register admin stylesheets and javascripts
54
+ *
55
+ * @param n/a
56
+ * @return n/a
57
+ */
58
+ add_action('admin_init','aj_admin_init');
59
+ function aj_admin_init() {
60
+ wp_register_style(
61
+ 'aj_admin_styles',
62
+ plugins_url('/css/admin.css',__FILE__)
63
+ );
64
+ wp_enqueue_style('aj_admin_styles');
65
+ wp_enqueue_script(
66
+ 'aj_admin_scripts',
67
+ plugins_url('/js/admin.js',__FILE__),
68
+ array('jquery'),
69
+ time()
70
+ );
71
+ }
72
+ /**
73
+ * async_javascript_menu()
74
+ *
75
+ * register admin menu
76
+ *
77
+ * @param n/a
78
+ * @return n/a
79
+ */
80
+ add_action('admin_menu','async_javascript_menu');
81
+ function async_javascript_menu() {
82
+ add_menu_page('Async Javascript Admin','Async Javascript','manage_options','async-javascript','async_javascript_admin');
83
+ }
84
+ /**
85
+ * async_javascript_admin()
86
+ *
87
+ * admin page
88
+ *
89
+ * @param n/a
90
+ * @return n/a
91
+ */
92
+ function async_javascript_admin() {
93
+ // Display settings saved message if optioned updated
94
+ if( isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' ) {
95
+ echo '<div class="updated"><p><strong>Settings saved.</strong></p></div>';
96
+ }
97
+ // load settings from database
98
+ $aj_enabled = (get_option('aj_enabled') == 1) ? array(true,'checked','') : array(false,'','style="display:none;"');
99
+ $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async';
100
+ $aj_exclusions = get_option('aj_exclusions');
101
+ $autoptimize_enabled = (get_option('autoptimize_enabled') == 1) ? 'checked' : '';
102
+ ?>
103
+ <div class="wrap">
104
+ <h2>Async Javascript Settings</h2>
105
+ <form action="options.php" method="post" name="options">
106
+ <?php echo wp_nonce_field('update-options'); ?>
107
+ <table class="form-table" width="100%" cellpadding="10">
108
+ <tbody>
109
+ <tr>
110
+ <td style="width:67%;">
111
+ <table class="form-table" width="100%" cellpadding="10">
112
+ <tbody>
113
+ <tr><td scope="row" align="left" colspan="2"><h3>Enable Async Javascript</h3></td></tr>
114
+ <tr><td scope="row" align="left" colspan="2">When you enable Async Javascript, when a script is loaded via the 'wp_enqueue_script' method, this plugin will add a 'async' or 'defer' attribute.</td></tr>
115
+ <tr><td scope="row" align="left" colspan="2">This action helps to eliminate render-blocking JavaScript in above-the-fold content. This can also help to increase your pagespeed which in turn will assist in improving your page ranking.</td></tr>
116
+ <tr>
117
+ <td scope="row" align="left" colspan="2">
118
+ There are several ways an external script can be executed:
119
+ <ul style="list-style:disc inside;">
120
+ <li>If async is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)</li>
121
+ <li>If async is not present and defer is present: The script is executed when the page has finished parsing</li>
122
+ <li>If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page</li>
123
+ </ul>
124
+ </td>
125
+ </tr>
126
+ <tr><td scope="row" align="left" colspan="2"><strong>Note: </strong>There have been instances where enabling Async Javascript has 'broken' the javascript delivery. Should this happen to you, I highly recommend installing the <a href="https://wordpress.org/plugins/autoptimize/" target="_blank">Autoptimize</a> plugin which will combine your javascript, further enhancing pagespeed and eliminating this issue.</td></tr>
127
+ <tr>
128
+ <td scope="row" align="left" style="width:20%;"><label>Enable Async Javascript</label></td>
129
+ <td scope="row" align="left"><input type="checkbox" name="aj_enabled" id="aj_enabled" value="1" <?php echo $aj_enabled[1]; ?> /></td>
130
+ </tr>
131
+ </tbody>
132
+ </table>
133
+ <table class="form-table aj_method" width="100%" cellpadding="10">
134
+ <tbody>
135
+ <tr><td scope="row" align="left" colspan="2"><h3>Async Javascript Method</h3></td></tr>
136
+ <tr><td scope="row" align="left" colspan="2">Please select the method (async or defer) that you wish to enable:</td></tr>
137
+ <tr>
138
+ <td scope="row" align="left" style="width:20%;">Method</td>
139
+ <td scope="row" align="left"><input type="radio" name="aj_method" value="async" <?php if ($aj_method == 'async') { echo 'checked'; } ?> /> Async <input type="radio" name="aj_method" value="defer" <?php if ($aj_method == 'defer') { echo 'checked'; } ?> /> Defer </td>
140
+ </tr>
141
+ </tbody>
142
+ </table>
143
+ <table class="form-table" width="100%" cellpadding="10">
144
+ <tbody>
145
+ <tr><td scope="row" align="left" colspan="2"><hr/><h3>Script Exclusion</h3></td></tr>
146
+ <tr><td scope="row" align="left" colspan="2"><hr/>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>
147
+ <tr>
148
+ <td scope="row" align="left" style="width:20%;">Exclusions</td>
149
+ <td scope="row" align="left"><textarea name="aj_exclusions" style="width:95%;"><?php echo $aj_exclusions; ?></textarea></td>
150
+ </tr>
151
+ </tbody>
152
+ </table>
153
+ <table class="form-table aj_method" width="100%" cellpadding="10">
154
+ <tbody>
155
+ <tr><td scope="row" align="left" colspan="2"><hr/><h3>Async Javascript For Plugins</h3></td></tr>
156
+ <tr><td scope="row" align="left" colspan="2"><hr/><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 email <a href="mailto:support@cloughit.com.au">support@cloughit.com.au</a></td></tr>
157
+ <?php
158
+ if (is_plugin_active('autoptimize/autoptimize.php')) {
159
+ ?>
160
+ <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>
161
+ <tr>
162
+ <td scope="row" align="left" style="width:20%;"><label>Enable Autoptimize Support</label></td>
163
+ <td scope="row" align="left"><input type="checkbox" name="autoptimize_enabled" value="1" <?php echo $autoptimize_enabled; ?> /></td>
164
+ </tr>
165
+ <?php
166
+ }
167
+ ?>
168
+ </tbody>
169
+ </table>
170
+ <input type="hidden" name="action" value="update" />
171
+ <input type="hidden" name="page_options" value="aj_enabled,aj_method,autoptimize_enabled,aj_exclusions" />
172
+ <input type="submit" name="Submit" value="Update" />
173
+ </td>
174
+ <td style="width:33%;">
175
+ <a href="http://cloughit.com.au/product/async-javascript-pro/" target="_blank"><img src="images/async-javascript-pro.jpg"</a>
176
+ </td>
177
+ </tr>
178
+ </tbody>
179
+ </table>
180
+ </form>
181
+ </div>
182
+ <?php
183
+ }
184
+ /**
185
+ * async_js()
186
+ *
187
+ * add 'async' attribute to '<script>' tasks called via wp_enqueue_script using the 'clean_url' filter
188
+ *
189
+ * @param string $url url being processed
190
+ * @return string $url modified url string
191
+ */
192
+ add_filter('clean_url','async_js',11);
193
+ function async_js($url) {
194
+ $aj_enabled = (get_option('aj_enabled') == 1) ? true : false;
195
+ $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async';
196
+ $aj_exclusions = get_option('aj_exclusions');
197
+ $array_exclusions = !empty($aj_exclusions) ? explode(',',$aj_exclusions) : $aj_exclusions;
198
+ if (false !== $aj_enabled && false === is_admin()) {
199
+ if (false === strpos($url,'.js')) {
200
+ return $url;
201
+ }
202
+ if (is_array($array_exclusions) && !empty($array_exclusions)) {
203
+ foreach ($array_exclusions as $exclusion) {
204
+ if (false !== strpos(strtolower($url),strtolower($exclusion))) {
205
+ return $url;
206
+ }
207
+ }
208
+ }
209
+ return $url . "' " . $aj_method . "='" . $aj_method;
210
+ }
211
+ return $url;
212
+ } // end async_js()
213
+ /**
214
+ * my_autoptimize_defer()
215
+ *
216
+ * Adds support for Autoptimize plugin. Adds 'async' attribute to '<script>' tasks called via autoptimize_filter_js_defer filter
217
+ * Autoptimize: https://wordpress.org/plugins/autoptimize/
218
+ *
219
+ * @param string $defer current value of $defer as passed to function
220
+ * @return string 'async' attribute
221
+ */
222
+ add_filter('autoptimize_filter_js_defer','my_autoptimize_defer',11);
223
+ function my_autoptimize_defer($defer) {
224
+ $aj_enabled = (get_option('aj_enabled') == 1) ? true : false;
225
+ $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async';
226
+ $autoptimize_enabled = (get_option('autoptimize_enabled') == 1) ? true : false;
227
+ if (false !== $aj_enabled && false === is_admin()) {
228
+ if (false !== $autoptimize_enabled) {
229
+ return " " . $aj_method . "='" . $aj_method . "' ";
230
+ }
231
+ }
232
+ }
233
+ ?>
css/admin.css CHANGED
@@ -1 +1,15 @@
1
- /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Plugin Name: Async Javascript
3
+ Plugin URI: http://www.cloughit.com.au/wordpress/plugins/async-javascript-wordpress-plugin/
4
+ Description: Async Javascript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
5
+ Version: 1.14.12.11
6
+ Author: David Clough (cloughit)
7
+ Author URI: http://www.cloughit.com.au/
8
+ Text Domain: async-javascript
9
+ License: GNU General Public License v2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+ */
12
+
13
+ .aj_method {
14
+ display:none;
15
+ }
images/async-javascript-pro.jpg ADDED
Binary file
js/admin.js CHANGED
@@ -1 +1,38 @@
1
- /*
2
  * isChecked()
3
  *
4
  * checks to see if the 'aj_enabled' checkbox is checked. If yes, show extended options, if no, hide extended options
5
  *
6
  * @param n/a
7
  * @return n/a
8
  */
9
  * functions and actions to load after document ready
10
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  * isChecked()
2
  *
3
  * checks to see if the 'aj_enabled' checkbox is checked. If yes, show extended options, if no, hide extended options
4
  *
5
  * @param n/a
6
  * @return n/a
7
  */
8
  * functions and actions to load after document ready
9
  */
10
+ /*
11
+ Plugin Name: Async Javascript
12
+ Plugin URI: http://www.cloughit.com.au/wordpress/plugins/async-javascript-wordpress-plugin/
13
+ Description: Async Javascript adds a 'async' or 'defer' attribute to scripts loaded via wp_enqueue_script
14
+ Version: 1.14.12.11
15
+ Author: David Clough (cloughit)
16
+ Author URI: http://www.cloughit.com.au/
17
+ Text Domain: async-javascript
18
+ License: GNU General Public License v2 or later
19
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
20
+ */
21
+
22
+ /**
23
+ * isChecked()
24
+ *
25
+ * checks to see if the 'aj_enabled' checkbox is checked. If yes, show extended options, if no, hide extended options
26
+ *
27
+ * @param n/a
28
+ * @return n/a
29
+ */
30
+ function isChecked() {
31
+ if (jQuery('#aj_enabled').prop('checked')) {
32
+ jQuery('.aj_method').show();
33
+ } else {
34
+ jQuery('.aj_method').hide();
35
+ }
36
+ }
37
+
38
+ /**
39
+ * functions and actions to load after document ready
40
+ */
41
+ jQuery(document).ready(function() {
42
+ isChecked();
43
+
44
+ jQuery(document).on('click','#aj_enabled',function() {
45
+ isChecked();
46
+ });
47
+ });
readme.txt CHANGED
@@ -1 +1,96 @@
1
- === Async Javascript ===
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Async Javascript ===
2
+ Contributors: (cloughit)
3
+ 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.4.2
7
+ Stable tag: 1.16.02.15
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Async Javascript adds a 'async' attribute to scripts loaded via wp_enqueue_script
12
+
13
+ == Description ==
14
+
15
+ 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 scripts 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
+ == Installation ==
22
+
23
+ Just install from your WordPress "Plugins | Add New" screen and all will be well. Manual installation is very straightforward as well:
24
+
25
+ 1. Upload the zip-file and unzip it in the /wp-content/plugins/ directory
26
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
27
+ 3. Go to `Async Javascript` menu to load setings page
28
+
29
+ == Frequently Asked Questions ==
30
+
31
+ = Which browsers support the 'async' attribute =
32
+
33
+ The 'async' attribute is new in HTML5. It is supported by the following browsers:
34
+
35
+ * Chrome
36
+ * IE 10 and higher
37
+ * Firefox 3.6 and higher
38
+ * Safari
39
+ * Opera
40
+
41
+ = Where can I report an error? =
42
+
43
+ Please lodge a support request at https://wordpress.org/support/plugin/async-javascript
44
+
45
+ = What information should I include when requesting support =
46
+
47
+
48
+ * A description of the problem, including screenshots and information from your browser's Error/ debug console
49
+ * URL of your blog (you can turn Async Javascript off, but should be willing to turn it briefly on to have the error visible)
50
+ * your Async Javascript settings (including a description of changes you made to the configuration to try to troubleshoot yourself)
51
+ * the Theme used (including the Theme's download link)
52
+ * optionally plugins used (if you suspect one or more plugins are raising havoc)
53
+
54
+ = I want out, how should I remove Async Javascript? =
55
+
56
+ * Disable the plugin
57
+ * Delete the plugin
58
+
59
+ == Screenshots ==
60
+
61
+ 1. this screen shot description corresponds to async-javascript-screenshot1.jpg and shows the admin page for Async Javascript
62
+
63
+ == Changelog ==
64
+
65
+ = 1.16.02.15 =
66
+
67
+ * NEW: Added information for Async Javascript Pro
68
+
69
+ = 1.15.02.23.1 =
70
+
71
+ * FIX: Code error fix
72
+
73
+ = 1.15.02.23 =
74
+
75
+ * NEW: Tested for WordPress v4.1.1
76
+ * NEW: Added ability to provide a comma seperated list of scripts to be excluded from async/defer (thanks to Nico Ryba for this suggestion)
77
+
78
+ = 1.14.12.19 =
79
+
80
+ * NEW: Tested for Wordpress v4.1
81
+
82
+ = 1.14.12.11.2 =
83
+
84
+ * FIX: Repaired broken SVN issue preventing plugin install
85
+
86
+ = 1.14.12.11.1 =
87
+
88
+ * FIX: Repaired broken SVN issue preventing plugin install
89
+
90
+ = 1.14.12.11 =
91
+
92
+ * FIX: Updated minor versioning issue
93
+
94
+ = 1.14.12.10 =
95
+
96
+ * Genesis