But client-side includes are inherently slower on first load than server-side includes, because they require an additional round trip to fetch the partial content.
That performance hit is particularly painful for the header. You either have to show a flash of content without the header, causing the page to jump around when the header loads in, or slow down the entire page while you wait for the second round-trip request.
"But what about subsequent page loads, where the header is in the browser's cache?" That's fine, but the savings are pretty minimal. Headers and footers are typically not a lot of bytes on the wire, so there's not a huge savings.
If all you want is the developer experience of writing HTML "by hand" without copying and pasting your header, server-side includes are a battle-tested solution.
In that case just flip it-- give links as data urls which hard-code the header/footer and which use a client-side include for the content. :)
Old links eternally provide the navigation the users know and love!
<!doctype html [
<!entity hdr system "header.html">
...
]>
&header <!-- content of header.html gets included here -->
... page body content goes here ...
SGML can also take care of inferring omitted <html>, <head>, and <body> tags here.Moreover, you can also use more sophisticated entity expansion and template mechanisms with type checking, proper HTML-aware auto-escaping (for things such as potentially malicious user-provided comments), table-of-content/nav generation, etc. etc.
Well, the way this would work... already exists. It would be just an iframe.
<INSERT SRC="a_quote.html">https://web.dev/articles/imports https://www.w3.org/TR/html-imports/
Functionally, it would be about the same? Caching would even largely go the way you want it to with it hitting the main layout page first, and then pulling in the content pages.
Edit: Amusingly, this organization strategy also provides a relatively easy way to try out other layouts. Since you can make a new driver page that iframes in your content.
With webcomponents, it's now trivial to do client-side includes. It's not really a missing feature anymore. See this post here (which, for some reason is being downvoted): https://news.ycombinator.com/item?id=40847759
Sure, but only for implementing your own. In practice they don't typically require the author of the page to know any Javascript. I'm using a client-side include by writing only HTML tags (with a 'remote-src' attribute).
It's no different from not having to know C++ in order to write HTML which is rendered by C++ code. The implementation just doesn't matter, because the user (in this case the page/site author) never needs to examine it.