Hacker News new | ask | show | jobs
by fergie 1253 days ago
But I just want to be able to specify a header or a footer in vanilla HTML...
2 comments

Although not vanilla HTML, server side includes are the closest to this that we've got. I use them quite extensively. This is basically what my boilerplate looks like:

  <!DOCTYPE html>
  <html lang="en" class="no-js">

  <head>
    <!--#include virtual="/ssi/head.html" -->

    <title></title>
    <meta name="description" content="">
  </head>

  <body>

    <header>
      <!--#include virtual="/ssi/header.html" -->
    </header>

    <main>
    </main>

    <footer>
      <!--#include virtual="/ssi/footer.html" -->
    </footer>

  </body>

  </html>
I'll put all my favicon, CSS, and other common head data in the /ssi/head.html file. Nice and simple and good enough for me. Can make it even more minimal by moving the <header> and <footer> tags into their respective SSI files.
Unfortunately SSIs dont work on s3 and some other plaforms, thereby negating their utility for running static sites on CDNs or keystores. But YES- why isn't there an SSI equivalent in the HTML spec?
> why isn't there an SSI equivalent in the HTML spec?

Because HTML Imports died in the spec drafting process. Unless you want a client-side SSI equivalent that doesn't require any JavaScript, HTML Imports wasn't that. I'm not aware of an alternative proposal that doesn't.

https://www.w3.org/TR/html-imports/

https://webmasters.stackexchange.com/questions/127482/on-wha...

What's stopping you? We've had flexbox and grid for quite a while now.
Pretty sure that you can't define an HTML snippet in one file and then include it in two or more other files using flexbox or grid? Or maybe I am wrong?
I do this using PHP. It gets the template file, the data and off you go.
Right- but you cant do it in plain HTML