- Script is a programming language that is interpreted and runs in the context of some other application (in this case, the browser).
- And client side implies that the script is executed on the client rather than getting submitted to the server giving a much better response to the user.
The SCRIPT tag can be either inside the HEAD tag or inside the BODY tag of the HTML document. The former is better in order to separate it from the actual HTML tags.
- It can be easily embedded within the HTML document.
- Have simple syntax and very easy to learn.
- Very easy to debug and test.
<TITLE>ALERT BOX EXAMPLE</TITLE>
alert("Welcome to Our Website!!!");
The welcome message will look like below when loaded in Google Chrome browser:
This indicates the content on the above the fold area is being blocked by the scripts on the page. This affects the loading speed as the content will be displayed only after the script files are loaded. The solution here could be to place the script files in the footer area of the page. Learn more on how to fix render-blocking scripts.
- Use less number of script files and combine multiple files.
- It is good idea to deliver the static script files using content delivery network (CDN).
- Use jQuery and Ajax library files from Google or any other CDN to improve the page loading speed.