Live data from Hacker News

Why can't HTML alone do includes?

frontendmasters.com

281–290 of 367 posts

Re: Why can't HTML alone do includes?

#281
post #74
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…

I think it feels off because an HTML file can include scripts, fonts, images, videos, styles, and probably a few other things. But not HTML. It can probably be coded with a custom element ( ). I would be surprised if there wasn't a github repo with something similar.

I created something like this relatively recently. The downside is of course that it requires JavaScript.

https://github.com/benstigsen/include.js

Re: Why can't HTML alone do includes?

#282

I too lamented the loss of HTML imports and ended up coming up with my own JavaScript library for it. https://miragecraft.com/blog/replacing-html-imports At the end of the day it’s not something trivial to implement at the HTML spec/parser level. For relative links, how should the page doing the import handle them? Do nothing and let it break, convert to absolute links, or remap it as a new relative link? Should the…

My guess is that some or maybe all of your concerns should have been solved by CSS @import (https://developer.mozilla.org/en-US/docs/Web/CSS/@import) although, as I'm reading the first few lines of the linked article, those must appear near the top of a CSS file, so are significantly more restricted than an import that can appear in the middle of a document.

Re: Why can't HTML alone do includes?

#284
post #17

This was the rabbit hole that I started down in the late 90s and still haven’t come out of. I was the webmaster of the Analog Science Fiction website and I was building tons of static pages, each with the same header and side bar. It drove me nuts. So I did some research and found out about Apache server side includes. Woo hoo! Keeping it DRY (before I knew DRY was a thing). Yeah, we’ve been solving this over and ove…

Don't Service Workers API provide this now, essentially act like a in-browser proxy to the server.

https://developer.mozilla.org/en-US/docs/Web/API/Service_Wor...

Re: Why can't HTML alone do includes?

#285

Fun fact: this does work with iframes: about contact The important part is that the target iframe must have a `name` attribute (not identified by `id`.) I guess, this is a legacy of framesets & frames. (Of course, this has all the issues of framesets, as in deep linking, accessibility, etc.)

The worst part of frames is scrolling.

You have to give an iframe a specific height in pixels. There is no “make this iframe the height its content wants to be (like normal HTML).

This leads to two options:

- your page has nested vertical scroll bars (awful UX) - you have to write JavaScript inside and outside the frame to constantly measure and communicate how tall the frame wants to be.

Or you could just not use frames.

Re: Why can't HTML alone do includes?

#286

This is just my own understanding, but doesn't a webpage consist of a bunch of nodes, which can be combined in any way. And an html document is supposed to be a complete set of nodes, so a combination of those won't be a single document anymore. Nodes can be addressed individually, but a document is the proportion for transmission containing also metadata. You can combined nodes as you like, but you can't really comb…

> a webpage consist of a bunch of nodes, which can be combined in any way More or less, but manipulating the nodes requires JavaScript, which some people would like to avoid.

I wasn't talking about the nodes in the DOM. I meant the minimal annotated information snippets, that the WWW is supposed to consist of, as opposed to the minimum addressable units.

Re: Why can't HTML alone do includes?

#287
post #17

This was the rabbit hole that I started down in the late 90s and still haven’t come out of. I was the webmaster of the Analog Science Fiction website and I was building tons of static pages, each with the same header and side bar. It drove me nuts. So I did some research and found out about Apache server side includes. Woo hoo! Keeping it DRY (before I knew DRY was a thing). Yeah, we’ve been solving this over and ove…

Don't Service Workers API provide this now, essentially act like a in-browser proxy to the server. https://developer.mozilla.org/en-US/docs/Web/API/Service_Wor...

Rational or not, some of us try very hard to avoid JavaScript based solutions.

Re: Why can't HTML alone do includes?

#288

On topic: what's the absolute minimal static site generator that can achieve this feature? I know things like Pelican can do it but it's pretty heavy. C preprocessor probably can be used for this...

Probably m4 aswell, but the syntax isn't really pretty by todays standards

Re: Why can't HTML alone do includes?

#289

Earlier quoted context omitted.

It's too bad we didn't go down the XHTML/semantic web route twenty years ago. Strict documents, reusable types, microformats, etc. would have put search into the hands of the masses rather than kept it in Google's unique domain. The web would have been more composible and P2P. We'd have been able to slurp first class article content, comments, contact details, factual information, addresses, etc., and built a wealth…

I don't think there was ever a sustainable route to a semantic web that would work for the masses. People wanted to write and publish. Only a small portion of people/institutions would have had the resources or appetite to tag factual information on their pages. Most people would have ignored the semantic taxonomies (or just wouldn't have published at all). I guess a small and insular semantic web is better than no s…

Also even if you do have good practices of semantic tagging, there are huge epistemological problems around taxonomies - who constructs them, what do the terms actually mean, how to organize them and so on.

In my experience trying to work with wikidata taxonomies, it can be a total mess when it's crowdsourced, and if you go to am "expert" derived taxonomy there are all kinds of other problems with coverage, meaning, democracy.

I've had a few flirtations with the semantic web going back to 2007 and long ago came to the personal conclusion that unfortunately AI is the only viable approach.

Re: Why can't HTML alone do includes?

#290
post #259

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.

It existed also in DTD (Document Type Definition) used with HTML 4 and below, and XML. Came fromn SGML too I guess.

Yes it did, and there are HTML 5.x DTDs for HTML versions newer than HTML 4.x ar [1], including post-HTML 5.2 review drafts until 2023; see notes at [2].

[1]: https://sgmljs.net/docs/html5.html

[2]: https://sgmljs.net/blog/blog2303.html

Post reply on HN