Locating a Web application's files is a simple matter during development (when design and organization is fresh in your memory), but it is not so easy when revisiting the application months after it has been deployed. While it's great to have well-written documentation at your fingertips in this scenario, a good organization of files and sensible naming convention can be just as valuable.
It's all in a name
I once worked with a developer who loved to name Web application files using vague names like a.html and x1.html. His philosophy centered on job security; he thought his presence would be necessary to know the functionality of a file with a mysterious name. Well, it didn't quite work out for him, as another developer was stuck wading through the mess of ambiguous filenames.
Providing a clue to developers is only one reason to use a consistent and clear naming convention for a Web application's resources. Here are a few guidelines for naming files:
- Do not include spaces in the filename. While it won't cause any problems with site functionality (as it is converted to %20), it leaves confusing file names that are less than pleasing to the eye.
- Avoid including special characters like the ampersand (&), pound sign (#) and question mark (?), as they may cause problems with the Web server when they are misinterpreted.
- Many sites use hyphens (-) and the underscore character (_) to avoid using spaces, but these are hard to memorize (which users may attempt).
- UNIX-based Web platforms are case-sensitive, so keep this in mind when naming resources.
- A file's extension (.aspx, .php, .html, .gif, etc.) should be valid, or properly map to the appropriate MIME type on the Web server.
These are simple guidelines that should not be too hard to follow, but I'm sure you've encountered sites that ignore them. Furthermore, we've all seen sites that have hard-to-remember filenames or, more simply, filenames that make no sense. Here are some good examples of filenames that make sense (or are easily remembered by users):
- Sites often include a page with information about the site or company, so include it in the about.html (or file extension appropriate to your Web platform).
- A site offering sports scores could use an easy-to-remember page name like scoreboard. A good example is the ESPN site, which offers scores using this approach.
- Many Web platforms utilize default files such as index.html or even default.html, so you must include these files. For example, ASP.NET uses default.aspx as its default page when a site is accessed (with no file specified). Web server settings can often be altered to use a file other than the default. Also, subdirectories utilize default filenames for each of the subdirectories on the server, so make sure each directory contains the necessary file.
At this point, you may be shaking your head and mumbling about dynamic filenames that you cannot control. The filenames generated by CMS tools or other platforms like Lotus Domino do strip you of filename control, so you will have to concentrate on directory and domain names.
Another area of a site closely related to files is directories. Please, do not be one of those developers that place all site resources in the base directory. There is nothing worse than scrolling through an endless list of files while trying to find a file—it is a mess. Site resources should be properly organized in an established (and documented) directory structure.
These top-level directories may contain subdirectories with files grouped accordingly. Like the previously described storefront directory, it may contain an images subdirectory with its image files. In addition, the image directory may be further subdivided into directories containing images for certain site areas or functionality.
Another area of naming for a Web application is the actual domain name. After all, what makes more sense http://www.techrepublic.com or tr.com? In addition, sub-areas of a site can be specified in the domain like TechRepublic, making areas accessible via their own address. For example, downloads are accessible via www.techrepublic.com/downloads and reviews may be viewed at www.techrepublic.com/reviews. In the end, it is all about choosing a name that makes sense and is easy to remember so users find it easier to return.
There is nothing more important than a name. Often, I find myself scratching my head as I navigate the countless files in a Web application that have no discernible directory structure or filenames that make sense. Keep these tips in mind when working on your next Web project.
Miss a column?
Check out the Web Development Zone archive, and catch up on the most recent editions of Tony Patton's column.
Tony Patton began his professional career as an application developer earning Java, VB, Lotus, and XML certifications to bolster his knowledge.
Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a production environment on a daily basis.