{"id":21779,"date":"2013-01-27T20:01:46","date_gmt":"2013-01-27T20:01:46","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/wp-deferred-javascripts\/"},"modified":"2016-09-01T08:54:21","modified_gmt":"2016-09-01T08:54:21","slug":"wp-deferred-javascripts","status":"publish","type":"plugin","link":"https:\/\/azb.wordpress.org\/plugins\/wp-deferred-javascripts\/","author":7706864,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"2.0.5","stable_tag":"2.0.5","tested":"4.6.30","requires":"3.0","requires_php":"","requires_plugins":"","header_name":"WP deferred javaScript","header_author":"Willy Bahuaud, Daniel Roch, Gr\u00e9gory Viguier","header_description":"","assets_banners_color":"52475a","last_updated":"2016-09-01 08:54:21","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"http:\/\/www.screenfeed.fr","header_author_uri":"https:\/\/wabeo.fr\/wp-deferred-js-authors.html","rating":3.2,"author_block_rating":0,"active_installs":900,"downloads":159209,"num_ratings":35,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":"11","2":"6","3":0,"4":"1","5":"17"},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":"974705","resolution":"128x128","location":"assets"},"icon-256x256.png":{"filename":"icon-256x256.png","revision":"974705","resolution":"256x256","location":"assets"}},"assets_banners":{"banner-772x250.jpg":{"filename":"banner-772x250.jpg","revision":"659847","resolution":"772x250","location":"assets"}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.5.2","1.5.3","1.5.4","1.5.5","1.5.6","2.0.0","2.0.1","2.0.2","2.0.5"],"block_files":[],"assets_screenshots":{"screenshot-1.jpg":{"filename":"screenshot-1.jpg","revision":"663726","resolution":"1","location":"assets"},"screenshot-2.jpg":{"filename":"screenshot-2.jpg","revision":"663726","resolution":"2","location":"assets"},"screenshot-3.jpg":{"filename":"screenshot-3.jpg","revision":"663726","resolution":"3","location":"assets"},"screenshot-4.jpg":{"filename":"screenshot-4.jpg","revision":"663726","resolution":"4","location":"assets"}},"screenshots":{"1":"Average load time of <strong>1.91<\/strong> seconds <strong>without WP Deferred JavaScripts activated<\/strong> and scripts loaded in the header","2":"Average load time of <strong>1.99<\/strong> seconds <strong>without WP Deferred JavaScripts activated<\/strong> and scripts queued in the footer","3":"Average load time of <strong>1.56<\/strong> seconds <strong>with WP Deferred JavaScripts activated<\/strong> and scripts queued in the header","4":"Average load time of <strong>1.54<\/strong> seconds <strong>with WP Deferred JavaScripts activated<\/strong> and scripts queued in the footer"},"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[68437,229,68438,187,247],"plugin_category":[52,54,59],"plugin_contributors":[80158,78484,80157],"plugin_business_model":[],"class_list":["post-21779","plugin","type-plugin","status-publish","hentry","plugin_tags-deferring","plugin_tags-javascript","plugin_tags-labjs","plugin_tags-optimization","plugin_tags-performance","plugin_category-performance","plugin_category-security-and-spam-protection","plugin_category-utilities-and-tools","plugin_contributors-confridin","plugin_contributors-greglone","plugin_contributors-willybahuaud","plugin_committers-confridin","plugin_committers-willybahuaud"],"banners":{"banner":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/banner-772x250.jpg?rev=659847","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/icon-128x128.png?rev=974705","icon_2x":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/icon-256x256.png?rev=974705","generated":false},"screenshots":[{"src":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/screenshot-1.jpg?rev=663726","caption":"Average load time of <strong>1.91<\/strong> seconds <strong>without WP Deferred JavaScripts activated<\/strong> and scripts loaded in the header"},{"src":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/screenshot-2.jpg?rev=663726","caption":"Average load time of <strong>1.99<\/strong> seconds <strong>without WP Deferred JavaScripts activated<\/strong> and scripts queued in the footer"},{"src":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/screenshot-3.jpg?rev=663726","caption":"Average load time of <strong>1.56<\/strong> seconds <strong>with WP Deferred JavaScripts activated<\/strong> and scripts queued in the header"},{"src":"https:\/\/ps.w.org\/wp-deferred-javascripts\/assets\/screenshot-4.jpg?rev=663726","caption":"Average load time of <strong>1.54<\/strong> seconds <strong>with WP Deferred JavaScripts activated<\/strong> and scripts queued in the footer"}],"raw_content":"<!--section=description-->\n<p>This plugin defer the loading of all JavaScripts added by the way of <code>wp_enqueue_script()<\/code>, using LABJS. The result is a significant optimization of loading time.<\/p>\n\n<p>It is compatible with all WordPress JavaScript functions (<code>wp_localize_script()<\/code>, js in header, in footer...) and works with all well coded plugins.<\/p>\n\n<p>If a plugin or a theme is not properly enqueuing scripts, your site may not work. Check this page: <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/wp_enqueue_script\">Function Reference\/wp_enqueue_script on WordPress Codex<\/a>.<\/p>\n\n<p>LABjs (Loading And Blocking JavaScript) is an open-source (MIT license) project supported by <a href=\"http:\/\/getify.com\/\">Getify Solutions<\/a>.<\/p>\n\n<p>We performed a range of tests to determine the potential benefit of loading time. On <a href=\"http:\/\/wabeo.fr\">wabeo<\/a> we executed <a href=\"http:\/\/webwait.com\/\">webwait<\/a> (150 calls by test). Result is this plugin could <strong>improve your loading time by 25%<\/strong>!!\nMore information in the <a href=\"http:\/\/wordpress.org\/extend\/plugins\/wp-deferred-javascripts\/screenshots\/\">Screenshots section<\/a>.<\/p>\n\n<p>You can find <a href=\"http:\/\/www.seomix.fr\/wp-deferred-javascript\/\">more information about WP Deferred JavaScripts<\/a> and <a href=\"http:\/\/wabeo.fr\/blog\/wordpress-javascripts-asynchrones\/\">technical information about asynchronous scripts<\/a> on authors blogs.<\/p>\n\n<!--section=installation-->\n<ol>\n<li><p>Upload the WP Deferred JavaScripts plugin to your blog and activate it.<\/p><\/li>\n<li><p>Enjoy ^^<\/p><\/li>\n<\/ol>\n\n<!--section=faq-->\n<p>WP Deferred JavaScript includes some hooks. If you never used one of them, <a href=\"http:\/\/codex.wordpress.org\/Plugin_API\">check this page<\/a>. It's better to use those filters in a plugin or a mu-plugin.<\/p>\n<dl>\n<dt>Exclude Scripts<\/dt>\n<dd><p><em>do_not_defer<\/em> is a filter that took as a parameter an array containing scripts that should be handle normally.<\/p>\n\n<p>Here is an example:<\/p>\n\n<pre><code>\/\/ Normal script enqueue.\nadd_action( 'wp_enqueue_scripts', 'register_canvas_script' );\nfunction register_canvas_script() {\n    wp_register_script( 'my-canvas-script', 'http:\/\/exemple.com\/myscript.js' );\n    wp_enqueue_script( 'my-canvas-script' );\n}\n\n\/\/ Don't defer this script.\nadd_filter( 'do_not_defer', 'exclude_canvas_script' );\nfunction exclude_canvas_script( $do_not_defer ) {\n    $do_not_defer[] = 'my-canvas-script';\n    return $do_not_defer;\n}\n<\/code><\/pre>\n\n<p><strong>Since 2.0.3 you can also use the WP Deferred JS settings pannel!<\/strong><\/p><\/dd>\n<dt>Change LABJS URL<\/dt>\n<dd><p><em>wdjs_labjs_src<\/em> is a filter that allow you to change LabJS URL.\n ($lab_src, $lab_ver)<\/p>\n\n<pre><code>\/\/ for example, I need a specific version of LabJS\nadd_filter( 'wdjs_labjs_src', 'my_labjs_src', 10, 2 );\nfunction my_labjs_src( $src, $ver ) {\n    if ( '2.0' !== $ver ) {\n        \/\/ Hotlinking raw github is a bad practice, I did it just for the lulz.\n        return 'https:\/\/raw.githubusercontent.com\/getify\/LABjs\/edb9fed40dc224bc03c338be938cb586ef397fa6\/LAB.min.js';\n    }\n    return $src;\n}\n<\/code><\/pre><\/dd>\n<dt>HTML5 compatibility<\/dt>\n<dd><p>If you use HTM5, <code>wdjs_use_html5<\/code> is a filter that remove the <code>type=\"text\/javascript\"<\/code> attribute. You can use it this way:<\/p>\n\n<pre><code>add_filter( 'wdjs_use_html5', '__return_true' );\n<\/code><\/pre><\/dd>\n<dt>Change a script URL<\/dt>\n<dd><p><em>wdjs_deferred_script_src<\/em> can be used to change the way one of the script is loaded. For example:<\/p>\n\n<pre><code>\/\/ Here, I need to add information about the charset.\nadd_filter( 'wdjs_deferred_script_src', '', 10, 3 );\nfunction change_my_script_src( $src_string, $handle, $src ) {\n    \/\/ $src_string -&gt; .script(\"http:\/\/exemple.com\/myscript.js?v=2.0\")\n    \/\/ $handle -&gt; my-script\n    \/\/ $src -&gt; http:\/\/exemple.com\/myscript.js?v=2.0\n    $out = array( 'src' =&gt; $src, 'charset' =&gt; 'iso-8859-1' );\n    return '.wait(' . json_encode( $out ) . ')';\n}\n<\/code><\/pre><\/dd>\n<dt>How to execute a code right after script loading<\/dt>\n<dd><p>You may need to execute a script right after its loading. You can use <em>wdjs_deferred_script_wait<\/em> filter to do it.<\/p>\n\n<pre><code>add_action( 'wdjs_deferred_script_wait', 'after_my_script', 10, 2 );\nfunction after_my_script( $wait, $handle ) {\n    if ( 'my-script' === $handle ) {\n        $wait = 'function(){new MyScriptObject();}';\n    }\n    return $wait;\n}\n<\/code><\/pre><\/dd>\n<dt>Execute a function when all scripts are loaded<\/dt>\n<dd><p>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.<\/p>\n\n<p>You will have to wrap this inline JS into a new function. Then, you will have to use <em>wdjs_before_end_lab<\/em> to execute it.<\/p>\n\n<pre><code>\/\/ This is a fake function that we are wrapping in a new function\nadd_filter( 'before_shitty_plugin_print_js', 'wrap_this_code' );\nfunction wrap_this_code( $code ) {\n    return 'function PluginShittyCode(){' . $code . '}';\n}\n\nadd_filter( 'wdjs_before_end_lab', 'call_shitty_code' );\nfunction call_shitty_code( $end ) {\n    $end .= '.PluginShittyCode()';\n    return $end;\n}\n<\/code><\/pre><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>2.0.5<\/h4>\n\n<ul>\n<li>Solve problem encountered on <a href=\"https:\/\/wordpress.org\/support\/topic\/problem-after-update-array_merge-argument-2-is-not-an-array?replies=2\">this support topic<\/a><\/li>\n<\/ul>\n\n<h4>2.0.4<\/h4>\n\n<ul>\n<li>do_not_defer can now accept scripts URI.<\/li>\n<li>New settings sub-pannel to exclude scripts from deferring, without using the plugin filter.<\/li>\n<li>Tested up to WordPress 4.4.2<\/li>\n<\/ul>\n\n<h4>2.0.2<\/h4>\n\n<ul>\n<li>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).<\/li>\n<\/ul>\n\n<h4>2.0.1<\/h4>\n\n<ul>\n<li>Small code improvement.<\/li>\n<li>Prefix functions with <code>wdjs<\/code> instead of <code>sfdjs<\/code>.<\/li>\n<\/ul>\n\n<h4>2.0.0<\/h4>\n\n<ul>\n<li>Overall code rewrite, by <a href=\"http:\/\/screenfeed.fr\">Gr\u00e9gory Viguier<\/a>.<\/li>\n<li>New hooks.<\/li>\n<li>LabJS is loaded now loaded asynchronously.<\/li>\n<li>Conditional script are now supported.<\/li>\n<li>Bug fix: 404 error on scripts without source.<\/li>\n<li>Script dependency that should not be deferred are now excluded automatically.<\/li>\n<li>WP Deferred JavaScripts is compatible with <a href=\"http:\/\/www.screenfeed.fr\/plugin-wp\/sf-cache-busting\/\">SF Cache Busting<\/a>.<\/li>\n<\/ul>\n\n<h4>1.5.5<\/h4>\n\n<ul>\n<li>Solve a problem when uri script contain \"&amp;\".<\/li>\n<li>Solve a bug while waiting dependencies.<\/li>\n<\/ul>\n\n<h4>1.5.4<\/h4>\n\n<ul>\n<li>Prevent bug when scripts dependencies are not enqueued.<\/li>\n<\/ul>\n\n<h4>1.5.3<\/h4>\n\n<ul>\n<li>Prevent a minor bug for footer enqueue script.<\/li>\n<\/ul>\n\n<h4>1.5.2<\/h4>\n\n<ul>\n<li>Fixed a minor bug: bad priority while emptying <code>$wp_scripts<\/code>.<\/li>\n<\/ul>\n\n<h4>1.5.1<\/h4>\n\n<ul>\n<li>Fixed a minor bug: plugin active was on login and register pages.<\/li>\n<\/ul>\n\n<h4>1.5<\/h4>\n\n<ul>\n<li>Fixed a major bug: plugin active only in front end.<\/li>\n<\/ul>\n\n<h4>1.4<\/h4>\n\n<ul>\n<li>Fixed a minor bug: some JavaScripts enqueued with very high priority were ignored - filter scripts are now hooked on <em>wp_print_scripts<\/em>.<\/li>\n<\/ul>\n\n<h4>1.3<\/h4>\n\n<ul>\n<li>Fixed a major bug: files with dependencies are now waiting the loading of parent files before loading themselves.<\/li>\n<\/ul>\n\n<h4>1.2<\/h4>\n\n<ul>\n<li>Data called after <em>wp_head<\/em>, but linked to a script queued into header are now considered by the plugin.<\/li>\n<\/ul>\n\n<h4>1.1<\/h4>\n\n<ul>\n<li>Correction of some minor bugs<\/li>\n<li>Improve code readability<\/li>\n<\/ul>\n\n<h4>1.0<\/h4>\n\n<ul>\n<li>Initial release<\/li>\n<\/ul>","raw_excerpt":"Defer the loading of all JavaScripts added with wp_enqueue_script(), using LABJS (an asynchronous javascript library).","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/21779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=21779"}],"author":[{"embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/willybahuaud"}],"wp:attachment":[{"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=21779"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=21779"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=21779"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=21779"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=21779"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/azb.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=21779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}