General Question
I have been researching how javascript is loaded when a page is being rendered. Particularly, I found this to be very helpful:
Where should I put <script> tags in HTML markup?
However, I can't seem to find any information about the differences between inline javascript vs a javascript include.
Assuming helloWorld.js is using identical code, is there any difference between how these will be loaded or run?
<script language="JavaScript" type="text/javascript" src="helloWorld.js"></script>
<script language="JavaScript" type="text/javascript">alert("hello world");</script>
My Implementation
More specifically, I am implementing Adobe Analytics. The implementation guide recommends putting the code on the page as follows:
<script language="JavaScript" type="text/javascript">
var s_code=s.t();if(s_code)document.write(s_code)
</script>
Would having this as an include rather than inline have any implications?
<script language="JavaScript" type="text/javascript" src="sCall.js"></script>
edit: I believe my question ended up being different because no one in the 'Similar Question' thread mentioned blocking.
Mladen Ilić answered my question.
Scripts without async or defer attributes, as well as inline scripts, are fetched and executed immediately, before the browser continues to parse the page.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
Thank you for your responses!
No matter how you include it, in both cases, code will be treated the same way and will have the same effect.
The only implications are maintenance and performance wise.
While it's clear that maintaining JS code which is in separate file is easier, when it comes to the performance, there are two things to consider:
My personal preference is to alway keep the JS separately.