Consider a situation where you have started a site that has a few pages. As the site becomes popular, you keep adding more and more pages to the site. So far, so good. Then you realize that your site could do even better if you added another section to the site. Once the section has been completed, you now need to make it accessible from all the pages of your site. With a few hundred pages to your site, you can well imagine the task ahead of you.
This is where Server Side Includes (SSI) comes to your help.
What is Server Side Includes (SSI) ? Server Side Includes are special codes that are embedded within the HTML of your page. When a browser requests your page from the server containing SSI, the server looks for and replaces the SSI code with information and sends it along with the rest of the page.
How does SSI work ? When the server sends a file with SSI commands in it, it reads each line of HTML in the file and looks for SSI commands. This is called parsing the file. When the server finds an SSI command, it processes the command and sends the result of the command to the browser. Since the SSI commands can occur any where in the HTML file, the server has to parse through the entire file. Parsing puts an extra burden on the server and so not all pages are parsed. To tell the server which pages to parse, most servers require that SSI pages must have the extension of “shtml” or “shtm”.
Syntax of SSI commands Because SSI commands are embedded in HTML, they have a special syntax which needs to be written exactly as defined otherwise the server is not able to differentiate between the SSI commands and the HTML. All SSI commands are written as extensions of the HTML comment. This ensures that if the server does not support SSI, then the page will still be sent to the browser and the SSI commands will not show up on your screen since they will be interpreted as comments. Every SSI command looks like this
-==-
It is necessary that the ending — must have a space before it.
Using SSI for design Server Side Includes started with the include command. This command allows you to include another file in the HTML file by a single command. The server then takes care of sending the included file as part of the main file to the browser. The include command looks like this:
-==-
The include command has two arguments and the table below explains when one argument should be used and when the other.
file — the file to include is in the current directory or a subdirectory of the current directory
virtual — Any path and file name that begins at the server root.
How does SSI simplify maintenance and design ? Using SSI it is possible to design an entire site such that it has a common file as an include for the header and another for the footer. This means that whenever there is a change in either the header or the footer, only one file needs to be modified and automatically the server will include the modified file the next time it needs to server a page for your site. So if you need to change the address on your site of over 1000 pages, you don’t need to change all the pages and upload them again. Just change the include file and all your pages will then show the new address. And you won’t have to worry about missing a file during correction either.
If you want to include a search button to your site, just modify the navigation bar include file, test it on one page and you will have the search button appear on all the pages of your site without any problems.
Server Side Includes require that your server work header to include the files than when serving regular html pages. This means that the server will slow down. But if you look as two pages one that is with includes and the other without includes, the difference in loading time would probably be so small that you would not notice it.
The advantage that you gain out of using SSI in having a site that is easy to maintain, is easily updated, allows you to reuse your HTML code, increases the reliability of the site and works far outweighs the overhead on the server.
Puneet Pawaia is a software developer and also the
web-master of Puneet Pawaia’s India Internet Resource
(http://www.pawaia.com) A site listing Indian ISPs,
CyberCafes in India, Hosting providers in India, Indian
portals etc.