Them it s gonna be a big big big time wasting kind of effort. So for that reason not a big fan. Some people like doing it and i suppose if you do it in the correct way then it s fine and that s just my personal preference. So what we re going to do now is jump back into the code and start adding.
Some script to our file. So here i am back in the index file and nothing has changed since the last time and we re going to start adding some scripts..
So the first way. I mentioned was between the script tags and i said we can do this in the head or the body. So we ll go ahead and put some in the head first of all so we open our script tag and we close it off and by the way in days gone by in the advent of the web site kind of technology era. We used to have to specify what type of script.
I ve already put an empty placeholder script out here which i ll delete and i ll paste this script in so i m going to save this and i m going to view it in a browser again okay so we still get that pop up. But this time notice that in the background. We ve loaded that webpage and that s because the browser has encountered this script right at the bottom of the html document at the bottom of the body tag. So it s already rendered all the rest of the web page.
So that s the script tag the next thing. We ll look at is adding an external script file. So i m going to copy this here. I m just going to cut it and i ll take out those script tags there and i m going to save this file and the next thing.
I m going to do is right click in this left. Pane create a new folder called scripts and within the folder. I m going to create a new file called main jx and within this main j s file. I m just going to copy what i did in the previous example.
The alert here so it s exactly the same script so we ll go back to our index file. Now and we re going to link to this script in our head and the way. We do this is by adding. The script tag again and we just need to specify a source and in the same way that we specify the source in the h.
Ref. Attribute here. We do it in the source. Attribute here now.
We want to do is jump into the scripts directory and then put a forward slash and then click the mink gf j. s file here so again we ve put this in the head so the browser should encounter..
Then it will load the rest of the page. I m going to jump back into the code and i m going to take this script tag. I m going to pop it right at the bottom of the body just like we did with the previous example and again. I m going to right click show an explorer and preview.
This and now you can see that the the documents loaded with the exception of the image for some reason. And i think that s just because it s taken a little longer to download the image before it s got to the script tag at. But again best practice dictates that you should put your scripts maybe at the bottom of the body tag. Like i say not always the case.
There s some exceptions to this rule. But as a beginner. I d always recommend popping your scripts in the bottom of your body tag. Okay.
The attribute for us so. If i put a double quote..
I ll do a course on that in the future. But just be aware of the different ways we can add it to our web page. So the takeaway from this are you can edit via the script tags in which case. I d 99 times out of 100 recommend that you put that at the bottom of your body tag.
Okay. So that s it for this lesson. If you have any questions whatsoever. Don t forget to comment below don t forget to subscribe also and i ll see you guys in the next lesson.
html, html basics, html tutorial, html lesson, html for beginners, html lesson for beginners, html tutorial for beginners, web design, web design tutorial, c…