Async JavaScript - Version 1.15.08.21.1

Version Description

Download this release

Release Info

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

Code changes from version 1.15.02.23.1 to 1.15.08.21.1

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