• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Creating Your First Scripts > Creating External JavaScript Files

Creating External JavaScript Files

Putting a script inside the page header isn't a problem if the script is relatively short. However, if your script (or scripts) take up dozens or hundreds of lines, it can make your HTML code look cluttered. Another problem you might run into is needing to use the same function (or functions) on multiple pages. Sure, you can just copy the code into each page that requires it, but if you make changes down the road, you need to update every page that uses the code.

The solution to both problems is to move the code out of the HTML file and into an external JavaScript file. This reduces the JavaScript presence in the HTML file to a single line (as you'll see shortly), and it means that you can update the code by editing only the external file.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint