Support » Plugin: Akismet Spam Protection » Akismet: Please load your JavaScript with defer, not async

  • Resolved roam92


    Hello Akismet Team,

    Thanks for a great plugin! I am optimizing my site and would like to help improve Akismet. This plugin currently makes the following request to load a JavaScript file:

    <script async="async" src='.../wp-content/plugins/akismet/_inc/form.js?ver=4.1.9' id='akismet-form-js'></script>

    So the plugin has hard-coded the async attribute in there. This is definitely better than not using anything.

    Both async and defer will load the JS file asynchronously – but using async will interrupt the parsing to run the loaded JavaScript, whereas using defer will not.

    With defer, the script will load in the background and then run when the DOM is fully built. So defer is definitely for better to use whenever possible.

    The problem is that you cannot defer a script that has already been async’ed (like with Akismet). If you try to specify both (like having an optimization plugin add defer), then the browser will always give async higher priority, thus negating the defer.

    So all this is to say that for best optimization and page loading speed, if the Akismet plugin removed async and used defer instead, it would be a better outcome. 🙂

    And the defer attribute enjoys very broad browser support:


    PS – Please also minify your JavaScript file while you’re at it. Appreciate it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Christopher Finke


    Because form.js is included almost immediately before the closing body tag, changing from async to defer is not likely to have much of an effect (if any), but I’ll run some tests this week and make that change as long as there aren’t any unintended consequences. Thanks for the feedback!

    Thread Starter roam92


    Great – thanks so much for your fast response, @cfinke !

    I can’t see how changing to defer could hurt, as it will still load asynchronously and there’s zero risk of interrupting the browser’s parsing to execute the file once loaded… So there seems no downside to doing it that way, but of course it’s always good to test and make sure!

    Also, do you think you could minify the JS file if you get the chance? It would save 100B of bandwidth when loading the file – which isn’t a ton, but definitely adds up when you multiply by 5+ million websites!

    Thanks again.

    Plugin Author Christopher Finke


    I’ve committed the switch to defer in

    Regarding minifying, I’m going to defer on that for now, as I feel that the value of end-users being able to easily read the Akismet JavaScript and see what it’s doing outweighs the bandwidth savings that minification brings.

    Thread Starter roam92


    Wow, that’s great to hear – thank you so much, Christopher!

    Really appreciate your help with the feedback and boosting performance.


Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.