What are some other ways to accomplish the equivalent of the ASP "include" command?
October 11, 2004 12:53 AM   Subscribe

What are some other ways to accomplish the equivalent of the ASP "include" command? (And if so, which is the easiest?) Is there any way to achieve the same effect with regular HTML?
posted by Jaybo to Computers & Internet (14 answers total)
 
Client-side HTML doesn't have an equivalent, though you could hack something up with javascript. It would however bad bad performance-wise. If your server supports it (most do), you could use however use server-side-includes, though they do cost more server resources than serving up static pages.
posted by fvw at 1:11 AM on October 11, 2004


If I could add one tag to HTML, it would be <include filename.htm> that loaded whichever page was referred into this spot in the original HTML document.

This seems so basic and useful, I wonder why it's never been added in some form already (as far as I know anyhow.)

It would give so much versatility to people designing basic web pages if there was a tag that allowed them to call other files - ie. "latestnews.html" or "upcoming.html" or whatever.

(And not to go off-topic before someone even answers my original question but are they any other tags you'd love to see in HTML which don't currently exist?)
posted by Jaybo at 1:12 AM on October 11, 2004


While it's not the same, for some purposes you could use the IFRAME tag.
posted by fvw at 1:14 AM on October 11, 2004


Is there any difference in server resources needed for an asp server execute and an ssi include?

I've always wondered which I should be using.
posted by monkey closet at 2:58 AM on October 11, 2004


SSI should never be more resource-intensive than using ASP, though if ASP interpretation is already built into the server (instead of requiring a separate interpreter) and is being used frequently already (i.e. it the interpreter isn't paged out) the difference is close to negligable. Still, if you don't care which and are resource-bound, use SSI.
posted by fvw at 5:13 AM on October 11, 2004


SSI, or a line of PHP.
posted by IshmaelGraves at 6:09 AM on October 11, 2004


PHP smells nicer than ASP. PHP includes.
posted by nthdegx at 7:01 AM on October 11, 2004


Jaybo- the reason it's that way, I think, is that web browsers expect each request to be complete and processes it in its entirety once the stream ends. Including another file, whether by SSI, ASP, PHP, or CF, always happens server-side, and one data stream is sent to the client. Browser's don't understand "wait here and go get the next part."

There probably is some obnoxiously convoluted way to do this via javascript and DOM.
posted by mkultra at 7:30 AM on October 11, 2004


That's not exactly a reason why it isn't possible. After all a lot of elements that are necessary for rendering are retrieved in separate requests. All in all, I think nobody thought the performance loss was worth not having to insert headers/footers server-side instead of client side, and so there was no demand for the feature.
posted by fvw at 8:31 AM on October 11, 2004


After all a lot of elements that are necessary for rendering are retrieved in separate requests.

How so? The entire text and layout of this page (except the style sheet) is retrieved in one request. There are separate requests for any images, but the page can render completely without them. If the contents of a frame or layer are retrieved separately, it doesn't change the fundamental that the master page itself is still completely "loaded". Or are we talking about something else?
posted by mkultra at 8:42 AM on October 11, 2004


After all a lot of elements that are necessary for rendering are retrieved in separate requests.

How so? The entire text and layout of this page (except the style sheet) is retrieved in one request. There are separate requests for any images, but the page can render completely without them.

You have a very different definition of "completely" from most people. In any case, browsers do wait for JavaScripts to be loaded before proceeding with rendering, since the script can have output that will change how the page is rendered. There's no reason something similar couldn't be done for non-script insertions.
posted by kindall at 9:32 AM on October 11, 2004


Actually, there's your answer, I think- the <SCRIPT SRC> tag calls a javascript whose sole method is document.write(). Wouldn't that do it?
posted by mkultra at 11:45 AM on October 11, 2004


One good possibility is to treat it as a production issue rather than a server issue. I routinely do this for small sites that aren't worth a full-fledged template system, or which for one reason or another don't want to depend on server-side code. If *all* you're doing is includes, then you probably shouldn't be doing it on the server anyway.

Build your content as HTML pages, using the hook of your choice wherever you want "include". Doesn't matter what, just something you can easily catch with a search-and-replace. When you're ready to release the site, run a macro or a quickie perl script or whatever on your dev box to replace those hooks with whatever you want to embed, storing the results in a different directory, then upload the results to the server. Later on if you want to change the header, you only have to change it in one place, re-run your macro, and away you go.

Most (if not all) html editors support this sort of thing natively; in BBEdit for example look under Markup -> Persistent Includes.
posted by ook at 2:32 PM on October 11, 2004


header thing you're including
posted by ook at 2:33 PM on October 11, 2004


« Older Using Miles to Upgrade   |   Technology Collusion? Newer »
This thread is closed to new comments.