Computer >> Computer tutorials >  >> Programming >> Javascript

What are the differences between inline JavaScript and External file?


The following are the difference between inline JavaScript and external file −

External scripts

  • The browser stores the external script once it is downloaded for the first time. If it is to be referenced again, then no additional download is needed.
  • This reduces download time and size.
  • The async and defer attributes have an effect. If these attributes are present the script will change the default behavior.

Inline scripts

  • Inline Scripts are executed immediately.
  • It gets loaded instantly and there is no need to trigger another request.
  • The async and defer attributes has no effect.
  • Inline Scripts are more useful for server-side dynamic rendering.