4 ms·
You can do client-side includes with iframes (or with JavaScript, e.g. a web component like `<include-fragment>`). https://www.webcomponents.org/element/include
by dfabulich 2y ago
You can do client-side includes with iframes (or with JavaScript, e.g. a web component like `<include-fragment>`). https://www.webcomponents.org/element/include-fragment-element https://www.webcomponents.org/element/include-fragment-eleme...
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.
- jancsika 2y ago> Headers and footers are typically not a lot of bytes on the wire, so there's not a huge savings. 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!