HTML Include: Separate Header and Footer
Asked Answered
G

2

2

Can we include an HTML file / snippet from another HTML file?

My use case is related to how a website is built; in a simple form, a site typically has the same header and footer across the board. It is pretty straightforward if the site is equipped with e.g. PHP so you can do something like the include statement; we can contain the header and footer in separate files and include them later. But, what if the site is purely static i.e. no "back-end" support?

One thing that I had done in the past is to utilize templates in Dreamweaver. This worked but I'd prefer something that is more product-independent.

Thanks.

Gypsie answered 22/8, 2011 at 22:19 Comment(0)
U
3

What you're looking for is Server Side Includes. It used to be available on most hostings, no idea what the situation is today.

Actually, a simple system based on a makefile and, why not, php's command line version, might also be helpful: a simple makefile that visits all php files in a directory, feeds it to php (eg, processes page decoration and stuff) and redirects the output to a corresponding html file should be enough to generate a set of uploadable, 100% static html files.

Upon answered 22/8, 2011 at 22:21 Comment(4)
Good call - I remember using SSI years ago. The alternative I think would be a frameset layout.Polder
@fvu: Thanks for the inputs. The SSI sounds simpler because it's pretty self-explanatory (e.g. you can make sense of it just by reading the comment / script on the HTML file). Is SSI still considered a good practice?Gypsie
@siku it's less common because in most cases at least some form of server side scripting is available, but SSI, if available at your host, is still for me a viable path.Upon
Adding as a side note, SSI is SEO friendly (just confirmed with a couple of SEO "experts").Gypsie
F
0

SSI is a great option if it is available to you as already suggested, I have always used PHP personally but as PHP is not available and if SSI isn't available then there is a JavaScript option as well.

The great thing with the JS option is the server doesn't need to have support for it due to the include scripts being client side. The bad thing is if the client doesn't have JS enabled in the browser the includes won't work. In saying that the vast majority of website users have JS enabled and this is displayed by most websites in the world who employ JS in 1 way or another.

Examples, the first one I found with a 2 second Google uses jQuery, have a look at the info here There are also some AJAX plugins that could potentially be used for this at the jQuery website if it is a path you're interested in going down.

I hope this helps you :-)

Fructiferous answered 22/8, 2011 at 22:52 Comment(2)
Thanks. Unfortunately, this technique is not SEO friendly (as also pointed out in the referenced article).Gypsie
Fair enough, there are similar techniques that are SEO friendly if you put a few minutes into Google or your favorite search engine! Good luckFructiferous

© 2022 - 2024 — McMap. All rights reserved.