Scripting your own page
Why script ?
Reasons for writing your own script:
- Popularity: A crucial factor in a website's popularity is download time. If your pages take a long time to download, boredom, frustration and even anger turn users away.
- Smaller file size: Writing your content into MSWord or Dreamweaver, and then asking them to convert it, gives you a file-size about 8 to 10 times larger than you can do yourself. View their code to see why. Their programing is atrocious. When these software fail to give you the formating or result you need, try manipulating their code to give the desired result. The time you think you save by using them is lost when maintaining your site.
- WYSIWYG: These two programs are not WYSIWYG: that is, what-you-see-is-NOT-what-you-get. For example, you set your page up beautifully in Word, then save from ".doc" to ".htm", and the result changes. Text boxes move; letters are chopped; lines move. Diagrams lose their meaning. Sometimes the diagrams are saved as larger than necessary files. Images may have unnecessarily large margins which make your pages look silly, and difficult to read.
- Debugging: Debugging pages scripted by MSWord and Dreamweaver, is a nightmare. Keep it simple, by scripting your own pages.
- Old computers: My clients usually are restricted to old computers and phone-lines, where download speed is very slow (often as slow as 1.5Kps), and connections fail quickly before files have finished arriving. At 1.5Kps, downloading an MSWord file of 200KB takes over 2 minutes whereas the same file scripted by you could take less than 15 seconds.
- Webhost: With my webhost, if my space on the server exceeds 1GB, I have to pay more. If my website's bandwidth (= filesize * number of files opened) exceeds 5GB per month I have to pay extra. Since my domain is non-profit (emphasis on ".org"), I do not have the money to pay extra, so I must keep my total server-space as low as possible.
- Professionalism: I honor my late father with my professionalism.
Easy scripting
Scripting is easy if:
- you make templates
- you stay within the bounds of your knowledge.
Initially, I found scripting frustrating and tedious because the standard xhtml gives a formating that I do not like. I experimented for months to develop the formating suited to my website. Now it is all templated, and I turn out pages quickly, with little thought, except when I try to do something unusual.
Your first template
These easy steps are:
- Open a text editor such as Notepad, and save as:
00_text_template.htm
The "00_" puts this file at the top of your files, where you can find it easily and quickly. Speed is important in web maintenance.
Do NOT use MSWord or Wordpad, and then copy and paste to Notepad – they may corrupt the page and you might never find the defect.
- Copy this red script onto your file's blank page.
- Each time you want to write another chapter for your website, open this template and save to another name.
- Isn't that easy ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>...</title>
</head>
<body>
<br /><br /><br /><br /><p style="text-align:center">© your_name</p><br /><br />
</body></html>
- Enter your content
Type your content between the tags: <body> </body>
- Link from your index
Now you must goto your index to link to this file.
Goto 2_index.htm.
The example given before has set up the links for you, so all you have to do, is fill in the file name (with its extension) and add a name for the link to display on the index frame. Easy.
- Check, debug
Check your syntax against the rules in the chapter Basic html.
All htm files will be opened by your browser, so just double-click. If cheeky Frontpage or similar software interferes, then right-click and drag down to [Open with...] from which you can select each of the browsers you have installed.
If it stalls then you have a defect, something euphemistically called a "bug". You must then debug your script by finding the defect. This is frustrating work, but becomes quicker with experience. Catalogue your hardest-to-find mistakes for future debugging sessions.
Some bugs can make later good-script act faultily, so if failed script looks error-free, check the script above it.
3 clicks maximum
Test my website against these rules and enjoy telling me where I have failed.
Rule 1: Your user should never be more than 3 clicks from the information he seeks. Currently my website has nearly 7000 files and eventually will have 30,000, yet no book is more than 3 clicks away after accessing the website, and the individual chapters require only another 2 clicks. The pages load very quickly, usually in less than 2 seconds, and the user watches the progress. (I am not boasting – it took many re-writes across many months to reach this efficiency.)
My index operates by expanding in front of the reader quickly down to book level, then a second index is cast above the window to give the chapters in each book. Because the indexes are very small, progress is fast; whereas opening whole pages prepared by Dreamweaver take ages.
Rule 2: The user must never become lost. Let the index be always visible, showing the path the user is taking. Then one click and the user is back Home. That is why the website I have given you has a frame devoted to the index. That index can keep expanding.
Rule 3: Speed, speed, speed. File size depends on the speed of your users' connection: Broadband, ADSL, or agonizing dial-up.
Files must open quickly so don't clutter with advertisements. If you must use images, use Photoshop or similar to reduce their filesize so they load in less than 5 seconds. It is better to use thumbnails of less than 2KB, as links so the user can choose whether or not he wants to lose time downloading them.
Test for the user's download time (when your website is up and running). Find a computer using dial-up and text. Would you be willing to wait this long, when you do not know if the site is worth it ?
Rule 4: Is the information that your user is seeking, clearly visible, or are there so many distractions your user becomes so frustrated he leaves, never to return ?
Rule 5: Study the script in the dot-point above to see how to do dot-points. Your dot-points will be different to mine because I use stylesheets, which you can study in the chapter Stylesheets.
Rule 6: Enjoy.
UTF-8
In the head of your xhtml file, you inserted the message:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
which tells the user's server that your encoding is in the character set called "utf-8".
If you copy and paste from a document editor like MSWord into your simple text editor like Notepad, you carry across curved quotes, hyphens, question marks, and other punctuation which are not members of the character set of utf-8. These must be replaced by your text editior (using Menu >> Edit >> Replace with ...).
Failing to do this, will cause the W#C validator to give an error like this :
Sorry, I am unable to validate this document because on line 179 it contained one or more bytes that I cannot interpret as utf-8 ...
or similar. You will then ask: where is line xxx ? (I was told "line 179" when there were only 140 lines in the file.)
When you see this vague message, guess the cause and seek those peculiar punctuation marks. For each punctuation, cut and paste it into the upper textfield of the Edit-Replace dialogue box, add your Notepad version to replace it, and click [Replace all].
Save, and Revalidate to see if you have solved the problem.