Javascript Defer (Async vs Defer)

Jul 27, 2018
Solving PageSpeed Insights - Remove render-blocking JavaScript
<script type="text/javascript">function appReady() {    // do something}</script><script defer src="/js/app.b5799d78449381e12b5d.js" onload="appReady()"></script>

When you use PageSpeed Insights, it shall complaint of Remove render-blocking JavaScript.

One of the way to solve this is using defer/async loading of JavaScript.

Defer vs Async

Refer to Script Tag - async & defer.

Defer

  • Guarantee order of exectution
  • Execute after HTML parser is completed

Async

  • No guarantee order of execution (suitable for js like Google Analytics)
  • Pause HTML parser to execute when finish downloading

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.