tags:

views:

197

answers:

7

Is it possible to reuse HTML tags across multiple files, headers and footers for example? Placing them in separate files adds an extra HTTP request, that I'd like to avoid.

I don't want to replicate minor changes in headers and footers across every html file every time a change request comes along.

+7  A: 

HTML is not a programming language - it's a markup language. You don't do object-oriented HTML because it isn't object based. This is the whole purpose of a server-side language, so you can make include files and use them in your server-side application.

If you have Apache however, you can use server-side includes which don't require a programming language such as PHP, but it's less flexible:

<!--#include virtual="/footer.html" -->
meder
You can do server side includes with IIS also.
klabranche
I know about server side includes. What I want to do is this. The files can be scattered during development. But I when I'm ready to release, a toolkit should compile the included files into a single html file.
gAMBOOKa
I'm confused - WHY can't you use a server-side language? If you're relying on something like php includes it wouldn't include each file as a separate HTTP request, it all becomes one HTTP request for the document you are feeding ( plus media resources like js/css ).
meder
We're using Java as our backend, the project manager is in no mood of listening to another server deployment(PHP). We use Ajax requests to fetch data, not JSP. So all are files front-facing files are HTTP extensions.
gAMBOOKa
A: 

HTML is not a programming language [2]. You can do that using JavaScript and AJAX, update contents without reloading the entire page. Gmail does that.

Havenard
+2  A: 

First, HTML isn't even a programming language, so it's impossible to have "Object-oriented" HTML.

Placing them in separate files adds an extra HTTP request, that I'd like to avoid.

If this is the reason for your "without server side code" requirement, then you are mistaken - the client does not fetch the templates that make up a page separately; the server side code will return a single HTML page to the client.

If, on the other hand, you don't have the option to run any server-side code at all and have to make do with static HTML pages, then there's only two options I can think of: iframes (which do result in separate HTTP requests, of course), or some sort of tool that basically runs the equivalent of server-side code to embed your reused templates everywhere and spits out the result to be uploaded to the server. You can have this effect by running a PHP/Apache-with-SSI/JSP/Whatever server on your development machine and using wget to make a static snapshot of the pages.

Michael Borgwardt
No, that's not my concern for avoiding server side code. We already have server side code and we use AJAX to fetch it.I curse you for mentioning the i word! Still, another HTTP request. Our application is inherently quite complex, so when I say I'm worried about HTTP requests, I mean at least half a dozen of 'em in each page. And I don't like relying of cache.
gAMBOOKa
A: 

Sure . But these would have to be separate ajax calls form the client . There are lot of javascript mvc frameworks like that do that .

Surya
A: 

If you want to have include files during development, then compile them into free-standing HTML files, you could do that by spidering your development server with wget: whatever server-side technology you use will combine the files and return the HTML, which wget will saves as one file.

AmbroseChapel
A: 

What I want to do is this. The files can be scattered during development. But I when I'm ready to release, a toolkit should compile the included files into a single html file.

You can use a template language/engine, such as jinja2.

You can layout files in a certain hierarchy, and have templates inherit from other templates, and include other templates, and define reusable macros (closest thing to what you referred to as "reusable tags").

hasen j
A: 

As everithing is object over the technology but not directly, indirectly interacting with the object that are created at different level as per security implementation.

Jagat Chand Yadav