admin_url( 'admin-ajax.php' ) ) ); register_setting( 'aj_options', 'aj_enabled' ); register_setting( 'aj_options', 'aj_method' ); register_setting( 'aj_options', 'aj_exclusions' ); register_setting( 'aj_options', 'aj_upgrade_notice' ); register_setting( 'aj_options', 'autoptimize_enabled' ); register_setting( 'aj_options', 'aj_autoptimize_enabled' ); $autoptimize_enabled = get_option('autoptimize_enabled'); $aj_autoptimize_enabled = get_option('aj_autoptimize_enabled'); if ( $autoptimize_enabled !== false && $aj_autoptimize_enabled === false ) { $aj_autoptimize_enabled = $autoptimize_enabled; update_option( 'aj_autoptimize_enabled', $aj_autoptimize_enabled ); delete_option( 'autoptimize_enabled' ); } } /** * async_javascript_menu() * * register admin menu * * @param n/a * @return n/a */ add_action( 'admin_notices', 'async_javascript_upgrade_notice' ); function async_javascript_upgrade_notice() { $aj_upgrade_notice = get_option( 'aj_upgrade_notice' ); if ( $aj_upgrade_notice != AJ_VERSION ) { echo '

Take full control with Async Javascript Pro. Read more...

'; } } /** * async_javascript_menu() * * register admin menu * * @param n/a * @return n/a */ add_action('admin_menu','async_javascript_menu'); function async_javascript_menu() { add_menu_page('Async Javascript Admin','Async Javascript','manage_options','async-javascript','async_javascript_admin'); } /** * async_javascript_admin() * * admin page * * @param n/a * @return n/a */ function async_javascript_admin() { // Display settings saved message if optioned updated if( isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true' ) { echo '

Settings saved.

'; } // load settings from database ?>

Async Javascript Settings

Enable Async Javascript

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.
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.
There are several ways an external script can be executed:
  • 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)
  • If async is not present and defer is present: The script is executed when the page has finished parsing
  • If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page
Note: There have been instances where enabling Async Javascript has 'broken' the javascript delivery. Should this happen to you, I highly recommend installing the Autoptimize plugin which will combine your javascript, further enhancing pagespeed and eliminating this issue.
/>

Async Javascript Method

Please select the method (async or defer) that you wish to enable:
Method /> Async /> Defer

Script Exclusion


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)
Exclusions

Async Javascript For Plugins


Note: 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 support@cloughit.com.au

Autoptimize -

/>
' tasks called via wp_enqueue_script using the 'clean_url' filter * * @param string $url url being processed * @return string $url modified url string */ add_filter('clean_url','async_js',11); function async_js($url) { $aj_enabled = (get_option('aj_enabled') == 1) ? true : false; $aj_method = (get_option('aj_method') != 'async') ? 'defer' : 'async'; $aj_exclusions = get_option('aj_exclusions'); $array_exclusions = !empty($aj_exclusions) ? explode(',',$aj_exclusions) : array(); if (false !== $aj_enabled && false === is_admin()) { if (false === strpos($url,'.js')) { return $url; } if (is_array($array_exclusions) && !empty($array_exclusions)) { foreach ($array_exclusions as $exclusion) { if ( $exclusion != '' ) { if (false !== strpos(strtolower($url),strtolower($exclusion))) { return $url; } } } } return $url . "' " . $aj_method . "='" . $aj_method; } return $url; } // end async_js() /** * my_autoptimize_defer() * * Adds support for Autoptimize plugin. Adds 'async' attribute to '