WordPress.org

Ideas

Non-blocking Asynchronous wp_enqueue_script

  1. redwallhp
    Member

    12345

    It would be cool if WordPress could optionally use a non-blocking asynchronous loader for scripts loaded through wp_enqueue_script. (Example: http://www.webmaster-source.com/2010/06/07/loading-javascript-asynchronously/)

    Wp_enqueue_script already has an argument that lets you move scripts to the bottom, so why not an option for async?

    Posted: 6 years ago #
  2. Paris Holley
    Member

    I have just released a plugin that does that:

    http://wordpress.org/extend/plugins/asynchronous-javascript/

    Posted: 3 years ago #
  3. webaware
    Member

    12345

    For anyone who needs this, there's a dirty hack from @toscho on the WordPress Stackexchange:

    http://wordpress.stackexchange.com/a/38335/24260

    Posted: 3 years ago #
  4. Phil
    Member

    I am reading...

    Since Version 4.1 a new filter has been introduced that finally provides a less painful solution to add async or defer attributes...

    http://matthewhorne.me/add-defer-async-attributes-to-wordpress-scripts/

    ===================

    Installed the plugin, seems to be working - although PSI now reckons head.js is blocking ? correct ? should I expect this ?

    Remove render-blocking JavaScript:
    /aynnchronous-javascript/js/head.load.min.js

    Posted: 1 year ago #
  5. tvexpert
    Member

    12345

    @Phil

    Got the same error here when downloading and using that plugin. No idea if it will be fixed, but a core implementation would be the way around..

    Posted: 6 months ago #
  6. Amrit Ray
    Member

    @Phil The solution in the link worked. But instead of the js handle, had to mention the actual js name. It added the "async" attribute to the js script tag.

    Posted: 4 months ago #
  7. huehnerstallkaufen1
    Member

    12345

    @Paris Holley

    Thank you so much for the plugin! It worked for me.

    Posted: 3 weeks ago #
  8. Clicknathan
    Member

    For those who prefer a non-plugin solution, this guy's post / code is working perfectly for me:

    https://ikreativ.com/async-with-wordpress-enqueue/

    Posted: 2 weeks ago #
  9. Paris Holley
    Member

    Keep in mind that async/defered will not work if your JS files have dependencies (ie: a jquery plugin needs jquery to be loaded first). The plugin I wrote could use some modernization (ie: determine if it can run pure async without doing head.js).

    Though nowadays, minimizing all of your scripts into a single file or even embedding directly into your page can be more performant than going async.

    Posted: 1 week ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    25 Votes
  • Status

    This idea is under consideration