HTML includes: separate header and footer

Is it possible to include an HTML file / fragment from another HTML file?

My use case is related to how a website is created; in simple form, the site usually has the same header and footer across the board. It is quite simple if the site is equipped with, for example, PHP so that you can do something like include ; we can contain the header and footer in separate files and include them later. But, what if the site is purely static, that is, there is no back-end support?

One thing I've done in the past is to use templates in Dreamweaver. It worked, but I would prefer something more independent of the product.

Thanks.

+2
html website dynamic-websites dreamweaver
source share
2 answers

What you are looking for, Server side includes . Previously, it was available on most hosting companies, I do not know what the situation is today.

In fact, a simple system based on a makefile and possibly not a php command line version may also be useful: a simple makefile that visits all php files in a directory, transfers it to php (for example, processes page layout and material) and redirects the output to the corresponding html file, should be enough to create a set of downloadable 100% static html files.

+3
source share

SSI is a great option if it is available to you, as already suggested, I always used PHP personally, but since PHP is not available, and if SSI is not available, there is also a JavaScript option.

The great thing about the JS option is that the server does not need support for it because include scripts are client-side. The bad thing is that if the client does not support JS in the browser, it will not work. Saying that the vast majority of website users have JS, and this is displayed by most websites in the world that use JS anyway.

Examples, the first one I found using the 2 second version of Google uses jQuery, see here . There are also some AJAX plugins that could potentially be used for this on the jQuery website, if that is the way you are interested.

Hope this helps you :-)

0
source share

All Articles