Live data from Hacker News

Why can't HTML alone do includes?

frontendmasters.com

201–210 of 367 posts

Re: Why can't HTML alone do includes?

#201

It's a pity, of all web resources advancements, js, css, runtimes, web engines. HTML was the most stagnant aspect of it, despite the "HTML5" effing hype. My guess is they did not want to empower HTML and threaten SSR's, or solutions. I believe the bigest concern of not making a step is the damned backward compatibility. Some just wont budge to move.

HTML5 hype started strong out of the gate because of the video and audio tags, and canvas slightly after. Those HTML tags were worth the hype.

Flash's reputation was quite low at the time and people were ready to finally move on from plugins being required on the web. (Though the "battle" then shifted to open vs. closed codecs.)

Re: Why can't HTML alone do includes?

#202
I 100% agree with the sentiment of this article. For my personal website, I write pretty much every page by hand, and I have a header and a footer on most of those pages. I certainly don't want to have to update every single page everytime I want to add a new navigation button to the top of the page. For a while I used PHP, but I was running a PHP server literally for only this feature. I eventually switched to JavaScript, but likewise, on a majority of my pages, this was the only JavaScript I had, and I wanted to have a "pure" HTML page for a multitude of reasons.

In the end, I settled on using a Caddy directive to do it. It still feels like a tacked on solution, but this is about as pure as I can get to just automatically "pasting" in the code, as described in the article.

Re: Why can't HTML alone do includes?

#203
post #34

"Includes" functionality is considered to be server-side, i.e. handled outside of the web browser. HTML is client-side, and really just a markup syntax, not a programming language. As the article says, the problem is a solved one. The "includes" issue is how every web design student learns about PHP. In most CMSes, "includes" become "template partials" and are one of the first things explained in the documentation. T…

> "Includes" functionality is considered to be server-side

Exactly! Include makes perfect sense on server-side.

But client-side include means that the client should be able to modify original DOM at unknown moment of time. Options are

1. at HTML parse time (before even DOM is generated). This requires synchronous request to server for the inclusion. Not desirable.

2. after DOM creation: (or whatever) needs to appear in the DOM, chunk loaded asynchronously and then the DOM element(sic!) needs to be replaced(or how?) by external fragment. This disables any existing DOM structure validation mechanism.

Having said that...

I've implemented in my Sciter engine using strategy #1. It works there as HTML in Sciter usually comes from local app resources / file system where price of issuing additional "get chunk" request is negligible.

See: https://docs.sciter.com/docs/HTML/html-include

Re: Why can't HTML alone do includes?

#204
post #198

Earlier quoted context omitted.

Images are content. Videos are content. Objects/iframes are content. The only one that is presentational is stylesheets.

Which (as I'm sure you know), also literally has 'content' :) https://developer.mozilla.org/en-US/docs/Web/CSS/content

True :)

Re: Why can't HTML alone do includes?

#205

You could start with something like this: customElements.define('html-import', class extends HTMLElement { connectedCallback() { const href = this.getAttribute('href') const fetch = new XMLHttpRequest() fetch.responseType = 'document' fetch.addEventListener('readystatechange', (function onfetch(e) { if (fetch.readyState !== XMLHttpRequest.DONE) return const document = fetch.response.querySelector('body') ?? fetch.res…

In one line

customElements.define("include", class extends HTMLElement { connectedCallback() { fetch(this.getAttribute("href")).then(x => x.text()).then(x => this.outerHTML = x) } })

Re: Why can't HTML alone do includes?

#206
post #91

You could start with something like this: customElements.define('html-import', class extends HTMLElement { connectedCallback() { const href = this.getAttribute('href') const fetch = new XMLHttpRequest() fetch.responseType = 'document' fetch.addEventListener('readystatechange', (function onfetch(e) { if (fetch.readyState !== XMLHttpRequest.DONE) return const document = fetch.response.querySelector('body') ?? fetch.res…

Well, that's not "HTML alone".

Could you use an object tag for this?

Re: Why can't HTML alone do includes?

#207

Initially HTML was less about the presentation layer and more about the "document" concept. Documents should be self-contained, outside of references to other documents.

One document == one HTML page was never the idea. Documents are often way too long to comfortably read and navigate that way. Breaking them into sections and linking between them was part of the core idea of HTML.

Includes are a standard part of many document systems. Headers and footers are a perfect example - if I update a document I certainly don't want to update the document revision number on every single page! It also allows you to add navigation between documents in a way that is easy to maintain.

LaTeX can do it. Microsoft Word can do it (in a typically horrible Microsoftian way). Why not HTML?

Re: Why can't HTML alone do includes?

#208

So glad I decided early in my career to not do webpages. Look how much discussion this minor feature has generated. I did make infra tools that outputted basic html, get post cgi type of stuff. What's funny is this stuff was deployed right before AWS was launched and a year later the on prem infra was sold and the warehouse services were moved to the cloud.

You and me both. I did some web dev back in the early days, and noped out when IE was dragging everyone down with its refusal to change. I have never had a reason to regret that decision.

Re: Why can't HTML alone do includes?

#209

The name of this feature is transclusion. https://en.wikipedia.org/wiki/Transclusion It was part of Project Xanadu, and originally considered to be an important feature of hypertext. Notably, mediawiki uses transclusion extensively. It sometimes feels like the wiki is the truest form of hypertext.

Ward Cunningham (inventor of the Wiki) spent some time trying to invent a transclusion-first wiki, where everyone had their own wiki-space and used transclusion socially https://en.wikipedia.org/wiki/Federated_Wiki

it never quite took off

Re: Why can't HTML alone do includes?

#210

HTML was historically an application of SGML, and SGML could do includes. You could define a new "entity", and if you created a "system" entity, you could refer to it later and have it substituted in. ]> .... &myheader; SGML is complex, so various efforts were made to simplify HTML, and that's one of the capabilities that was dropped along the way.

Well, that is an entire attack surface, on it's own.

https://en.wikipedia.org/wiki/Billion_laughs_attack

Post reply on HN