Store Your JavaScript Code in a .js File
In my last post, I told you I was going to show beginners how to store their JavaScript code in a .js file to improve their code to text content ratio. Today, I fulfill my promise.
The first step is to create a new document in Notepad, Dreamweaver or your favorite text editor and save that file with a .js extension (eg. “anyfilename.js”).
Now cut the JavaScript code from the HTML source code of your web page and paste it into your new .js file. Make sure you remove the opening and closing SCRIPT tags from your pasted content.
Finally, add the following code to the HEAD of your HTML document:
<SCRIPT LANGUAGE="javascript" SRC="anyfilename.js"></SCRIPT>
Save your HTML and .js files and publish them to the web. Voila!



One Response to “Store Your JavaScript Code in a .js File”
1 Web Design Blog - Web Design & Toast » Blog Archive » Hide your Mailto: Email Address from Spambots with JavaScript 15 September 2006 @ 9:55 am
[…] If you want to be extra tricky, take the code you placed in the HEAD of your document and store it in a .js file to reduce the amount of code in your HTML page and make your email address even more invisible to spambots. […]
Leave a Reply
You must be logged in to post a comment.