What are the differences between inline JavaScript and External file?

JavascriptWeb DevelopmentFront End Technology

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.
raja
Published on 16-Jan-2018 15:09:57
Advertisements