RE: Missing Functionality: Include

Elliot Jenner wrote:
> 
> Coming from programming languages like C++ and Python, I naturally
> expected that it would be similarly simple to move redundant parts of
> the page into external files and then include them back in. After
> extensive searching, I determined that this basic functionality is
> missing from the language, and requires such hefty workarounds as
> server-side-scripting or PHP.

Perhaps it is because HTML is not a *programming* language, but rather a
mark-up language, two very different animals.  HTML (Hyper Text Markup
Language) is about applying structure and meaning to text, and not about
spinning wheels, dancing flames or other wondrous adventures; it is about
conveying meaning to your data and information.

> It should not be necessary to go to a
> completely different language to perform such a necessary task,
> particularly languages that require the added complication of a web
> server just to see if your code is functioning properly, and the added
> worry that some servers may not support the scripting.

Say what? Hefty? At the most basic level, Apache web servers allowed you to
do just this since nearly the beginning of time itself, simply by adding:

<!--#include virtual="/foo.html" -->

And ensuring that your server (your compiler as it were) was configured to
respect that command.  See: 
http://httpd.apache.org/docs/1.3/howto/ssi.html 

Subsequently, with PHP it is as simple as: 

<?php
include ("/foo.html");
?>

And again ensuring that your server is configured correctly.  Pretty much
every installation of Apache today offers PHP support out of the box.

Not using Apache?  IIS also allows for server-side inclusion via ASP:

<!-- #INCLUDE FILE="../includes/foo.asp" --> 

<!-- #INCLUDE VIRTUAL="/myweb/includes/foo.asp" -->  

Again out of the box.  These are 'hefty'?


As for testing; if you are looking to use PHP, investigate XAMPP (windows)
or XAMPP for Mac OS X - both allow for local testing without the need to
'upload' anything.  Want Windows testing, try starting here:
http://support.microsoft.com/kb/839013




> 
> Am I alone in wishing for a simple <include url('file.html')/> element
> or something similar that allows this to be accomplished easily?

See above (SSI).  The three 'planks' of modern web development continue to
be HTML for semantic structure, CSS for 'display', and scripting (client
side or server side) for 'functionality', and I for one hope it remains this
way.  As an aside, while server-side scripting *does* have a higher cost to
the developer (server and bandwidth), it is also a more predictable method,
and as such is likely the better choice for functionality such as what you
are seeking (IMHO). I'm still not a big AJAX guy, but believe that there is
a means using xmlhttprequest to also do something similar


> In my
> opinion this is a completely basic function that any language should
> have. How did CSS, which was developed later, obtain the <link> tag,
> meanwhile the older HTML standard still lacks it?

As others have pointed out, <link> in HTML existed prior to CSS, and was
simply used in the early days to link an external CSS file to an HTML
document.  We also now have @import...

> Particularly on a
> website, there will always be bits of code that are common to all the
> various pages that make it up, for example the navigation and copy
> write/contact code.

Yep, those requirements have been around for some time now (certainly the
decade or so that I've been playing here), but understanding the history of
what came before will hopefully clarify both reasoning and current
methodologies better.

Cheers!

JF

Received on Tuesday, 12 May 2009 01:05:29 UTC