Since I've been doing Web site development, I've been wondering why HTML does not include an <include> tag.
Almost every programming language I've worked with over the years has some kind of inclusion capability. Most often called "include" (but more recently also "using") its purpose is to add content from one file while processing another. In other words, file X has some code that I want to use in file B, so I have a language statement in file B that says "Include X." To the program processing file B, it is as if the contents of file X replaced the include statement at that exact spot.
For decades, programmers have demanded includes as a practical, time-saving matter. When HTML came around, somehow all that technical genius overlooked them.
Some point out that HTML does support includes with server-side languages like ASP, PHP, and even the server-side SSI. But I counter that HTML already has some forms of include on the client side. We can include DOCTYPES, images, script files, CSS, and objects on the client-side, all processed by the browser and requiring no server-side processing whatsoever.
It seems to me that a generic include facility in HTML would be extremely useful. Consider the following:
- <include type="text/css" src="site.css" />
- <include type="text/javascript" src="jquery.1.3.min.js" />
- <include type="image/png" src="baby-photo.png" />
- <include type="text/html" src="left-menu.htm" />
In one consistent tag, all forms of content external to the current file can be included. Of the four examples above, three are recognizable as forms of tags that already exist - linkrel, script, and img. Only the fourth, plain text, has no HTML equivalent.
I realize that there is one catch - by definition, a valid HTML file is supposed to well-formed, which means at least that it begins and ends with an <html> tag. But with an included file, it is highly desirable to bring in just fragments. For example, my "menu.htm" example above might simply contain a <div> with the contents of a menu. Many HTML editors throw an error when a user tries to save an HTML type file that does not follow the rules. I argue that the browser can easily strip extraneous tags while processing the include, bringing in only the germ and not the chaff.
This strikes me as simplicity itself. Perhaps I'm missing something.
Tags: HTML, Programming, Web
A total of 39 related articles were found. See them all...