2.4. Establishing a Naming Convention for Your Files

Problem

You need to name web page files so they convey meaningful information to your visitors—as well as you and others who work on the site.

Solution

Web server file naming should follow the same guidelines discussed in Recipe 2.3: you should avoid spaces and special characters, use other punctuation sparingly, and keep them all lowercase. Unlike a web site directory—whose primary, if not only, purpose is to organize and contain site files—the files themselves are on the site for a variety of reasons. A one-size-fits-all naming scheme won't work. The right way to name a downloadable PDF file differs from the right way to name a GIF file of the site logo because the two files have different purposes.

Despite their differences, all the files on your site should have names that:

  • Have a valid file extension, such as .html, .gif, or .pdf

  • Convey something about the source, contents, or nature of the file

  • Follow a logical and consistent scheme across similar files

Discussion

The various files on your site come together on pages, the Web's most basic building block. As files themselves, your HTML pages have filenaming requirements depending on where they exist in the site structure. I'll cover some of those issues first, and then address some additional guidelines to consider when naming supporting files such as images and downloads.

Index pages

As its name suggests, the index page offers an overview of the contents of the directory and provides ...

Get Web Site Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.