Title: WP Deferred JavaScripts
Author: Willy Bahuaud
Published: <strong>ژانویه 27, 2013</strong>
Last modified: سپتامبر 1, 2016

---

Search plugins

![](https://ps.w.org/wp-deferred-javascripts/assets/banner-772x250.jpg?rev=659847)

This plugin **hasn’t been tested with the latest 3 major releases of WordPress**.
It may no longer be maintained or supported and may have compatibility issues when
used with more recent versions of WordPress.

![](https://ps.w.org/wp-deferred-javascripts/assets/icon-256x256.png?rev=974705)

# WP Deferred JavaScripts

 By [Willy Bahuaud](https://profiles.wordpress.org/willybahuaud/)

[Download](https://downloads.wordpress.org/plugin/wp-deferred-javascripts.2.0.5.zip)

 * [Details](https://azb.wordpress.org/plugins/wp-deferred-javascripts/#description)
 * [Reviews](https://azb.wordpress.org/plugins/wp-deferred-javascripts/#reviews)
 *  [Installation](https://azb.wordpress.org/plugins/wp-deferred-javascripts/#installation)
 * [Development](https://azb.wordpress.org/plugins/wp-deferred-javascripts/#developers)

 [Support](https://wordpress.org/support/plugin/wp-deferred-javascripts/)

## Description

This plugin defer the loading of all JavaScripts added by the way of `wp_enqueue_script()`,
using LABJS. The result is a significant optimization of loading time.

It is compatible with all WordPress JavaScript functions (`wp_localize_script()`,
js in header, in footer…) and works with all well coded plugins.

If a plugin or a theme is not properly enqueuing scripts, your site may not work.
Check this page: [Function Reference/wp_enqueue_script on WordPress Codex](https://codex.wordpress.org/Function_Reference/wp_enqueue_script).

LABjs (Loading And Blocking JavaScript) is an open-source (MIT license) project 
supported by [Getify Solutions](http://getify.com/).

We performed a range of tests to determine the potential benefit of loading time.
On [wabeo](http://wabeo.fr) we executed [webwait](http://webwait.com/) (150 calls
by test). Result is this plugin could **improve your loading time by 25%**!!
 More
information in the [Screenshots section](https://wordpress.org/extend/plugins/wp-deferred-javascripts/screenshots/).

You can find [more information about WP Deferred JavaScripts](http://www.seomix.fr/wp-deferred-javascript/)
and [technical information about asynchronous scripts](http://wabeo.fr/blog/wordpress-javascripts-asynchrones/)
on authors blogs.

## Screenshots

 * [[
 * Average load time of **1.91** seconds **without WP Deferred JavaScripts activated**
   and scripts loaded in the header
 * [[
 * Average load time of **1.99** seconds **without WP Deferred JavaScripts activated**
   and scripts queued in the footer
 * [[
 * Average load time of **1.56** seconds **with WP Deferred JavaScripts activated**
   and scripts queued in the header
 * [[
 * Average load time of **1.54** seconds **with WP Deferred JavaScripts activated**
   and scripts queued in the footer

## Installation

 1. Upload the WP Deferred JavaScripts plugin to your blog and activate it.
 2. Enjoy ^^

## FAQ

WP Deferred JavaScript includes some hooks. If you never used one of them, [check this page](https://codex.wordpress.org/Plugin_API).
It’s better to use those filters in a plugin or a mu-plugin.

  Exclude Scripts

_do\_not\_defer_ is a filter that took as a parameter an array containing scripts
that should be handle normally.

Here is an example:

    ```
    // Normal script enqueue.
    add_action( 'wp_enqueue_scripts', 'register_canvas_script' );
    function register_canvas_script() {
        wp_register_script( 'my-canvas-script', 'http://exemple.com/myscript.js' );
        wp_enqueue_script( 'my-canvas-script' );
    }

    // Don't defer this script.
    add_filter( 'do_not_defer', 'exclude_canvas_script' );
    function exclude_canvas_script( $do_not_defer ) {
        $do_not_defer[] = 'my-canvas-script';
        return $do_not_defer;
    }
    ```

**Since 2.0.3 you can also use the WP Deferred JS settings pannel!**

  Change LABJS URL

_wdjs\_labjs\_src_ is a filter that allow you to change LabJS URL.
 ($lab_src, $
lab_ver)

    ```
    // for example, I need a specific version of LabJS
    add_filter( 'wdjs_labjs_src', 'my_labjs_src', 10, 2 );
    function my_labjs_src( $src, $ver ) {
        if ( '2.0' !== $ver ) {
            // Hotlinking raw github is a bad practice, I did it just for the lulz.
            return 'https://raw.githubusercontent.com/getify/LABjs/edb9fed40dc224bc03c338be938cb586ef397fa6/LAB.min.js';
        }
        return $src;
    }
    ```

  HTML5 compatibility

If you use HTM5, `wdjs_use_html5` is a filter that remove the `type="text/javascript"`
attribute. You can use it this way:

    ```
    add_filter( 'wdjs_use_html5', '__return_true' );
    ```

  Change a script URL

_wdjs\_deferred\_script\_src_ can be used to change the way one of the script is
loaded. For example:

    ```
    // Here, I need to add information about the charset.
    add_filter( 'wdjs_deferred_script_src', '', 10, 3 );
    function change_my_script_src( $src_string, $handle, $src ) {
        // $src_string -> .script("http://exemple.com/myscript.js?v=2.0")
        // $handle -> my-script
        // $src -> http://exemple.com/myscript.js?v=2.0
        $out = array( 'src' => $src, 'charset' => 'iso-8859-1' );
        return '.wait(' . json_encode( $out ) . ')';
    }
    ```

  How to execute a code right after script loading

You may need to execute a script right after its loading. You can use _wdjs\_deferred\
_script\_wait_ filter to do it.

    ```
    add_action( 'wdjs_deferred_script_wait', 'after_my_script', 10, 2 );
    function after_my_script( $wait, $handle ) {
        if ( 'my-script' === $handle ) {
            $wait = 'function(){new MyScriptObject();}';
        }
        return $wait;
    }
    ```

  Execute a function when all scripts are loaded

You may have to use inline JavaScript in your footer. If that’s the case, you will
have to use that last hook to make it compatible with WP Deferred JavaScripts.

You will have to wrap this inline JS into a new function. Then, you will have to
use _wdjs\_before\_end\_lab_ to execute it.

    ```
    // This is a fake function that we are wrapping in a new function
    add_filter( 'before_shitty_plugin_print_js', 'wrap_this_code' );
    function wrap_this_code( $code ) {
        return 'function PluginShittyCode(){' . $code . '}';
    }

    add_filter( 'wdjs_before_end_lab', 'call_shitty_code' );
    function call_shitty_code( $end ) {
        $end .= '.PluginShittyCode()';
        return $end;
    }
    ```

## Reviews

![](https://secure.gravatar.com/avatar/dcfc9e725e033c628fb236b28b0a22a328d811b9e868f1533cc32e6d7bb2f770?
s=60&d=retro&r=g)

### 󠀁[Conflict with Visual Composer](https://wordpress.org/support/topic/conflict-with-visual-composer-44/)󠁿

 [webstpro](https://profiles.wordpress.org/webstpro/) نوامبر 13, 2018

This plugin prevents showing on the navigation menu on some pages when used with
Visual Composer.

![](https://secure.gravatar.com/avatar/8c87b98e3f3c3b97ca030d14619a0e40bb8fde76d27e6ff1545f48739a7d7c8f?
s=60&d=retro&r=g)

### 󠀁[Ineffective Plugin w/ No Support](https://wordpress.org/support/topic/ineffective-plugin-w-no-support/)󠁿

 [Todd Farino](https://profiles.wordpress.org/tfarino/) مئی 3, 2018

Like everyone else, I wanted to speed up my site and deferring javaScript is a must.
The problem is this plugin does more damage than it helps. – Stops drop down menus
in Avada from working. – Google Maps, broke. – Sliders, some break. ZERO explanation
as to how to exclude certain javascript form deferring. Went to the support board,
and they help no one. Good idea, but needs allot of work!

![](https://secure.gravatar.com/avatar/435592ea534e9aace6cfd76d7fc037d298263b5a17329adeb4ad063bc993ac51?
s=60&d=retro&r=g)

### 󠀁[Great! Use if you need to fine tune speed of your website](https://wordpress.org/support/topic/great-use-if-you-need-to-fine-tune-speed-of-your-website/)󠁿

 [capbussat](https://profiles.wordpress.org/capbussat/) مارس 27, 2018

Great! Easy to use if you need to fine tune speed of your web. There is a need to
spped up web downloading, after cache you can use this to optimize Javascript download.
But it needs fine tuning otherwise you will get some strange results like pages 
that do not render properly for a few seconds. Always begin by using a cache plugin.

![](https://secure.gravatar.com/avatar/ecc227769daefb7a818965d0dae0efb2811d4a5535ca6a00ebea98820290c685?
s=60&d=retro&r=g)

### 󠀁[Can break other stuff, hard to trace back](https://wordpress.org/support/topic/can-break-other-stuff-hard-to-trace-back/)󠁿

 [Joris Le Blansch](https://profiles.wordpress.org/apiosys/) نوامبر 21, 2017

For instance breaks Ajax in Contact 7. To avoid IMO.

![](https://secure.gravatar.com/avatar/6b5184da7f4cbeb40db919c32e3605750cbb1bcd6d67fe2945c11c335d50002c?
s=60&d=retro&r=g)

### 󠀁[Google maps are not working with this plugins](https://wordpress.org/support/topic/google-maps-are-not-working-with-this-plugins/)󠁿

 [Emanuel Pietri](https://profiles.wordpress.org/emanuel-pietri/) آقوست 19, 2017

Hi there. Unfortunately i must inform you this plugins broken my Google maps. We
need other plugins for resolving referring problem.

![](https://secure.gravatar.com/avatar/ba88bf725172171dd4d55620f545d747aa464cb4f8ecf5168299085cbe12f7f5?
s=60&d=retro&r=g)

### 󠀁[Works Perfectly – Negative Reviews are due to Plugin Conflicts](https://wordpress.org/support/topic/works-perfectly-negative-reviews-are-due-to-plugin-conflicts/)󠁿

 [tigershroof](https://profiles.wordpress.org/tigershroof/) مئی 1, 2017

Okie, so tested this right now with more than 16 different configurations and it
works very well. It is the only plugin that actively defers JS. Rest are not as 
effective. If you are using any Caching Plugin, it may conflict with your website
and may break your site. In 16 tests, nothing like this happened. Tested with PHP7
and latest Version of Wordpress.

 [ Read all 35 reviews ](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/)

## Contributors & Developers

“WP Deferred JavaScripts” is open source software. The following people have contributed
to this plugin.

Contributors

 *   [ Willy Bahuaud ](https://profiles.wordpress.org/willybahuaud/)
 *   [ Daniel Roch ](https://profiles.wordpress.org/confridin/)
 *   [ Grégory Viguier ](https://profiles.wordpress.org/greglone/)

“WP Deferred JavaScripts” has been translated into 1 locale. Thank you to [the translators](https://translate.wordpress.org/projects/wp-plugins/wp-deferred-javascripts/contributors)
for their contributions.

[Translate “WP Deferred JavaScripts” into your language.](https://translate.wordpress.org/projects/wp-plugins/wp-deferred-javascripts)

### Interested in development?

[Browse the code](https://plugins.trac.wordpress.org/browser/wp-deferred-javascripts/),
check out the [SVN repository](https://plugins.svn.wordpress.org/wp-deferred-javascripts/),
or subscribe to the [development log](https://plugins.trac.wordpress.org/log/wp-deferred-javascripts/)
by [RSS](https://plugins.trac.wordpress.org/log/wp-deferred-javascripts/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

#### 2.0.5

 * Solve problem encountered on [this support topic](https://wordpress.org/support/topic/problem-after-update-array_merge-argument-2-is-not-an-array?replies=2)

#### 2.0.4

 * do_not_defer can now accept scripts URI.
 * New settings sub-pannel to exclude scripts from deferring, without using the 
   plugin filter.
 * Tested up to WordPress 4.4.2

#### 2.0.2

 * Minor bugfix: now the plugin catches some data added lately and include it in
   the plugin script tag (instead of letting the data create its own tag).

#### 2.0.1

 * Small code improvement.
 * Prefix functions with `wdjs` instead of `sfdjs`.

#### 2.0.0

 * Overall code rewrite, by [Grégory Viguier](http://screenfeed.fr).
 * New hooks.
 * LabJS is loaded now loaded asynchronously.
 * Conditional script are now supported.
 * Bug fix: 404 error on scripts without source.
 * Script dependency that should not be deferred are now excluded automatically.
 * WP Deferred JavaScripts is compatible with [SF Cache Busting](http://www.screenfeed.fr/plugin-wp/sf-cache-busting/).

#### 1.5.5

 * Solve a problem when uri script contain “&”.
 * Solve a bug while waiting dependencies.

#### 1.5.4

 * Prevent bug when scripts dependencies are not enqueued.

#### 1.5.3

 * Prevent a minor bug for footer enqueue script.

#### 1.5.2

 * Fixed a minor bug: bad priority while emptying `$wp_scripts`.

#### 1.5.1

 * Fixed a minor bug: plugin active was on login and register pages.

#### 1.5

 * Fixed a major bug: plugin active only in front end.

#### 1.4

 * Fixed a minor bug: some JavaScripts enqueued with very high priority were ignored–
   filter scripts are now hooked on _wp\_print\_scripts_.

#### 1.3

 * Fixed a major bug: files with dependencies are now waiting the loading of parent
   files before loading themselves.

#### 1.2

 * Data called after _wp\_head_, but linked to a script queued into header are now
   considered by the plugin.

#### 1.1

 * Correction of some minor bugs
 * Improve code readability

#### 1.0

 * Initial release

## Meta

 *  Version **2.0.5**
 *  Last updated **10 ایل‌لر ago**
 *  Active installations **900+**
 *  WordPress version ** 3.0 or higher **
 *  Tested up to **4.6.30**
 *  Languages
 * [English (US)](https://wordpress.org/plugins/wp-deferred-javascripts/) و [French (France)](https://fr.wordpress.org/plugins/wp-deferred-javascripts/).
 *  [Translate into your language](https://translate.wordpress.org/projects/wp-plugins/wp-deferred-javascripts)
 * Tags
 * [javascript](https://azb.wordpress.org/plugins/tags/javascript/)[optimization](https://azb.wordpress.org/plugins/tags/optimization/)
   [performance](https://azb.wordpress.org/plugins/tags/performance/)
 *  [Advanced View](https://azb.wordpress.org/plugins/wp-deferred-javascripts/advanced/)

## Ratings

 3.2 out of 5 stars.

 *  [  17 5-star reviews     ](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/?filter=5)
 *  [  1 4-star review     ](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/?filter=3)
 *  [  6 2-star reviews     ](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/?filter=2)
 *  [  11 1-star reviews     ](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/?filter=1)

[Add my review](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/wp-deferred-javascripts/reviews/)

## Contributors

 *   [ Willy Bahuaud ](https://profiles.wordpress.org/willybahuaud/)
 *   [ Daniel Roch ](https://profiles.wordpress.org/confridin/)
 *   [ Grégory Viguier ](https://profiles.wordpress.org/greglone/)

## Support

Got something to say? Need help?

 [View support forum](https://wordpress.org/support/plugin/wp-deferred-javascripts/)