Akismet: Please load your JavaScript with defer, not async
-
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
asyncattribute in there. This is definitely better than not using anything.Both
asyncanddeferwill load the JS file asynchronously – but usingasyncwill interrupt the parsing to run the loaded JavaScript, whereas usingdeferwill not.With
defer, the script will load in the background and then run when the DOM is fully built. Sodeferis 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 giveasynchigher priority, thus negating thedefer.So all this is to say that for best optimization and page loading speed, if the Akismet plugin removed
asyncand useddeferinstead, it would be a better outcome. 🙂https://flaviocopes.com/javascript-async-defer/
https://javascript.info/script-async-defer
https://stackoverflow.com/questions/10808109/script-tag-async-defer
And the
deferattribute enjoys very broad browser support:https://caniuse.com/script-defer
Thanks!
PS – Please also minify your JavaScript file while you’re at it. Appreciate it!
The topic ‘Akismet: Please load your JavaScript with defer, not async’ is closed to new replies.