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
async
attribute in there. This is definitely better than not using anything.Both
async
anddefer
will load the JS file asynchronously – but usingasync
will interrupt the parsing to run the loaded JavaScript, whereas usingdefer
will not.With
defer
, the script will load in the background and then run when the DOM is fully built. Sodefer
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 giveasync
higher priority, thus negating thedefer
.So all this is to say that for best optimization and page loading speed, if the Akismet plugin removed
async
and useddefer
instead, 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
defer
attribute 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.