Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Objects Includes and iframes

Boris Vukobrat
Boris Vukobrat
4,248 Points

Code reuse in HTML

Is it a good practice to iframe a header, for example, so using same small html file for header around entire site?

3 Answers

Austin Whipple
Austin Whipple
29,725 Points

Using a server-side scripting language for simply including template files might be a bit of overkill. Server-side includes (.shtml files), would likely be the easiest and doesn't require knowledge of another programing language to accomplish what you're after.

EDIT: Probably not a great idea to use iFrames for this either due to styling problems and potentially ugly code.

geoffrey
geoffrey
28,736 Points

It's honestly a good question, in my recents projects I 've used a server side language such as PHP, so I have a separated file for the header named header.php, and this one is included everytime in each page, if needed.

But I've never thought about that for a static website, I've searched on google and It seems some people tell It's good, while some others tell It's not...

Maybe Nick Pettit could enlight us on this point.

Boris Vukobrat
Boris Vukobrat
4,248 Points

There is also a JS and jQuery solutions, which are perhaps better then PHP in some situations.

Maybe, W3 Consortium will introduce in HTML6 an attribute for header like

<header src="my_header.html">

: ))

Santiago Blanco
Santiago Blanco
2,939 Points

You can use angular and create your owns directives and reuse html. Or maybe you want to try with polymer.