DEV Community


Discussion on: Do you need async and/or defer?

jmau111 profile image
Julien Maury Author


In the post :

The best-case scenario for async is when you need support for modern browsers only, and your script is entirely standalone, with no dependencies, so you don't expect results from other scripts to run your code

I think Google Analytics is compatible with that

In your comment :

if you depend on something in the DOM but you fire the function at intervals or on an even

I did not think about that usage here, thanks for sharing. I will check it.

And defer is a good choice for something that interacts with the DOM but is not essential to the page looking presentable. Like a chatbot tab or image gallery.

agree with you, defer is not critical. However, it can significantly improve performances in some conditions.

Forem Open with the Forem app