WordPress.org

Ideas

Non-blocking Asynchronous wp_enqueue_script

  1. gewinnspiele
    Member

    12345

    @Paris Holley

    Great! Thank you for the plugin! It worked for me.

    Posted: 2 years ago #
  2. jamesdlow
    Inactive

    The first time I need it, I was really surprised this wasn't built in. We shouldn't really have to be reduced to filters and hacks to get this attribute added.

    Hope they can add this update soon!

    Posted: 2 years ago #
  3. Ralf Koller
    Inactive

    12345

    If an option for the async attribute would be added it would be welcome as well too add an option for defer alongside as well

    Posted: 2 years ago #
  4. swdeveloper
    Member

    If your wordpress version is 4.1 or higher you can use 'script_loader_tag' filter. For example:

    function change_to_async($tag, $handle) {
    'your-js-script' == $handle ? str_replace( ' src', ' async="async" src', $tag ): $tag;
    }
    
    add_filter('script_loader_tag', 'change_to_async');
    Posted: 1 year ago #
  5. GreatBlakes
    Inactive

    12345

    I'm also using the custom string replace method myself with success, but it feels so hacky.

    I'm still hoping that WordPress core will have an implementation of this in the future. I'm honestly surprised it has gone this long without.

    Posted: 10 months ago #
  6. cj42
    Member

    It would be interesting to be able to 'preload' stylesheet. So far, the wp_enqueue_style function does not enable that, since there is no way to attach the 'preload' value to the 'rel' attribute in a <link>.

    This is especially useful for page speed and optimisation. A good use case is preloading fonts :

    https://www.freecodecamp.org/news/web-fonts-in-2018-f191a48367e8/#preload-fonts

    https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content

    Posted: 2 months ago #
  7. secretlab.pw
    Member

    Since https://developers.google.com/speed/pagespeed/insights/ increased requirements to website speed, almost impossible to get green points for both mobile and desktop.

    So something should be done with CSS/JS loading queue especially with huge popularity of drag & drop builder. Most of the "premium" themes now are slow in the red zone of the Google test.

    Posted: 1 month ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    44 Votes
  • Status

    This idea is under consideration