You Need SSI Right Now!
Category: Website Design and Development | Date: 2003-10-25 |
I learned of SSI (Server Side Includes) long before I built my current site. Since it seemed the only way to go, I checked it out once again for the new site to be.
What SSI amounts to is creating a new page for any elements common to all pages on your site. Then ask the server to include these pages whenever main pages are requested.
For example, build a regular HTML page containing all the content, including graphics, as is often used in the left column of a page as the basis of navigation. Then, instead of adding this content to each page, simply include the file. And hey, its super. If you need to make a change, you make it only once, instead of on every page on your site.
SSI Slows Page Downloads?
What prevented me initially from using SSI were notes I read regards increasing page download time. Each page using included files needs to parsed (read) by the server to find any files to be included. Being an absolute fanatic about minimizing page download speed, I passed. Bad mistake.
Updating Multiple Pages Chews Up Time
Six month later, changing a single menu item was taking hours. I decided to ignore the page download time and go. But I ran into another snag. Pages with includes need the SHTML extension, else the server wont parse them. (An S in front of HTML.)
Switching From HTML to SHTML Busts Links
Nuts. I already had lots of incoming links. Since I didnt want to bust them by changing file names, I passed once again.
I had heard people speak of ways in which a server in some cases could be instructed to treat HTML pages as SHTML pages. But I didnt check it out. Another bad mistake.
The Perfect Solution
Many months later I ran across the following code. Add these lines to the top of your .htaccess file, and all existing HTML files will be parsed just as if they had the .SHTML extension. Neat. No changes in file names, which means no busted incoming links.
Options Includes
AddType text/html .html
AddHandler server-parsed .html
.htaccess is a hidden file in the root directory on your server. It is helpful in doing many things, and can be located elsewhere as needed, but for now lets focus on the above.
In WS_FTP, when you type -al into the blank field to the right, this file name will become visible. The best plan is to download the file, add the above code, then upload and overwrite the original. (The reason for downloading first is to be certain you hold whatever the file may already contain.)
Creating Files
What I did next was create a file, yleftnav.html, containing all the content in the left column of a page. Then on each page, I replaced the content in that column with the following.
!--#include file="yleftnav.html"--
Given the three lines above in the .htaccess file, each .HTML file is parsed for the include command. When found, the content of the file is included in the page at that point. You can see the results by viewing the source for one of my pages. And you can view the file included with ...
http://sitetipsandtricks.com/yleftnav.html
The display of this page will be distorted, but it works fine when constrained by the first cell/column on each site page.
Im also using ybotnav.html for the text links and contact info at the bottom of each page. Anything repeated on most or all pages can be handled in this way.
Finally Getting To It
I continued to avoid the chore for many months. And when I did get to it, hours disappeared quickly, for by then I had more pages.
But hey, I do love it. And theres good news besides. Those notes regards slowing page downloads (theyre still around), appear to have applied in an earlier time when servers were slower. I havent detected any increase in the download time for the pages on my site.
Get to this right now, before your site grows even larger. Whatever time it takes will be saved many times over on future changes required.
Test First
Before getting carried away, be sure to test to see that whatever code you choose works properly on your host server. If it does not, and your host cant help you, then you may be stuck with renaming page name extensions to .SHTML. Which also means changing links internal to your site. And losing any links to your site. (Even this option isnt available on all hosts.)
An Alternative
Here is another include command I am not using on my site. It assumes all files to be included are in /includes/, a subdirectory within the directory containing your pages.
!--#include virtual="includes/includefile.html"--
Since my site layout is simple, and includes only three subdirectories for pages, I simply uploaded the files to be included to these three directories, and to the root directory. For me, this is a great solution for it takes only minutes to upload four copies. You might do better, however, with the above.
Further Resources
What triggered me into action was Jennifer Johnsons article, "How To Avoid Website Growing Pains." Shes been trying to talk me into using SSI for years. I should have listened to her and got to it sooner. (And so should you!) Heres a link to her article.
http://sitetipsandtricks.com/art/a091101b.html
Heres a page from Webopedia given a search on SSI. Lots of great info referenced here. Follow the link to Yahoo for a couple more. As a reminder, that bit about slowing download speed is included in one of the referenced articles. Id ignore this, for I found no degradation at all.
http://www.webopedia.com/TERM/S/SSI.html
Wrapping Up
I should have done this years ago. Do it now. Or youll be saying the same thing in a year or so. Honest, you will!
About the Author
Bob McElwain
Want to build a winning site? Improve one you already have? Fix one thats busted? Get ANSWERS. Subscribe to "STAT News" now! join-stat@lyris.dundee.net
Web marketing and consulting since 1993
Site: http://sitetipsandtricks.com
Phone: 209-742-6349
email - mc@sierratel.com
url - http://www.sitetipsandtricks.com
mc@sierratel.com
http://www.sitetipsandtricks.com
What SSI amounts to is creating a new page for any elements common to all pages on your site. Then ask the server to include these pages whenever main pages are requested.
For example, build a regular HTML page containing all the content, including graphics, as is often used in the left column of a page as the basis of navigation. Then, instead of adding this content to each page, simply include the file. And hey, its super. If you need to make a change, you make it only once, instead of on every page on your site.
SSI Slows Page Downloads?
What prevented me initially from using SSI were notes I read regards increasing page download time. Each page using included files needs to parsed (read) by the server to find any files to be included. Being an absolute fanatic about minimizing page download speed, I passed. Bad mistake.
Updating Multiple Pages Chews Up Time
Six month later, changing a single menu item was taking hours. I decided to ignore the page download time and go. But I ran into another snag. Pages with includes need the SHTML extension, else the server wont parse them. (An S in front of HTML.)
Switching From HTML to SHTML Busts Links
Nuts. I already had lots of incoming links. Since I didnt want to bust them by changing file names, I passed once again.
I had heard people speak of ways in which a server in some cases could be instructed to treat HTML pages as SHTML pages. But I didnt check it out. Another bad mistake.
The Perfect Solution
Many months later I ran across the following code. Add these lines to the top of your .htaccess file, and all existing HTML files will be parsed just as if they had the .SHTML extension. Neat. No changes in file names, which means no busted incoming links.
Options Includes
AddType text/html .html
AddHandler server-parsed .html
.htaccess is a hidden file in the root directory on your server. It is helpful in doing many things, and can be located elsewhere as needed, but for now lets focus on the above.
In WS_FTP, when you type -al into the blank field to the right, this file name will become visible. The best plan is to download the file, add the above code, then upload and overwrite the original. (The reason for downloading first is to be certain you hold whatever the file may already contain.)
Creating Files
What I did next was create a file, yleftnav.html, containing all the content in the left column of a page. Then on each page, I replaced the content in that column with the following.
!--#include file="yleftnav.html"--
Given the three lines above in the .htaccess file, each .HTML file is parsed for the include command. When found, the content of the file is included in the page at that point. You can see the results by viewing the source for one of my pages. And you can view the file included with ...
http://sitetipsandtricks.com/yleftnav.html
The display of this page will be distorted, but it works fine when constrained by the first cell/column on each site page.
Im also using ybotnav.html for the text links and contact info at the bottom of each page. Anything repeated on most or all pages can be handled in this way.
Finally Getting To It
I continued to avoid the chore for many months. And when I did get to it, hours disappeared quickly, for by then I had more pages.
But hey, I do love it. And theres good news besides. Those notes regards slowing page downloads (theyre still around), appear to have applied in an earlier time when servers were slower. I havent detected any increase in the download time for the pages on my site.
Get to this right now, before your site grows even larger. Whatever time it takes will be saved many times over on future changes required.
Test First
Before getting carried away, be sure to test to see that whatever code you choose works properly on your host server. If it does not, and your host cant help you, then you may be stuck with renaming page name extensions to .SHTML. Which also means changing links internal to your site. And losing any links to your site. (Even this option isnt available on all hosts.)
An Alternative
Here is another include command I am not using on my site. It assumes all files to be included are in /includes/, a subdirectory within the directory containing your pages.
!--#include virtual="includes/includefile.html"--
Since my site layout is simple, and includes only three subdirectories for pages, I simply uploaded the files to be included to these three directories, and to the root directory. For me, this is a great solution for it takes only minutes to upload four copies. You might do better, however, with the above.
Further Resources
What triggered me into action was Jennifer Johnsons article, "How To Avoid Website Growing Pains." Shes been trying to talk me into using SSI for years. I should have listened to her and got to it sooner. (And so should you!) Heres a link to her article.
http://sitetipsandtricks.com/art/a091101b.html
Heres a page from Webopedia given a search on SSI. Lots of great info referenced here. Follow the link to Yahoo for a couple more. As a reminder, that bit about slowing download speed is included in one of the referenced articles. Id ignore this, for I found no degradation at all.
http://www.webopedia.com/TERM/S/SSI.html
Wrapping Up
I should have done this years ago. Do it now. Or youll be saying the same thing in a year or so. Honest, you will!
About the Author
Bob McElwain
Want to build a winning site? Improve one you already have? Fix one thats busted? Get ANSWERS. Subscribe to "STAT News" now! join-stat@lyris.dundee.net
Web marketing and consulting since 1993
Site: http://sitetipsandtricks.com
Phone: 209-742-6349
email - mc@sierratel.com
url - http://www.sitetipsandtricks.com
mc@sierratel.com
http://www.sitetipsandtricks.com
Copyright © 2005-2006 Powered by Custom PHP Programming