Live data from Hacker News

Why can't HTML alone do includes?

frontendmasters.com

271–280 of 367 posts

Re: Why can't HTML alone do includes?

#271

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…

Someone else made the same - https://github.com/Paul-Browne/HTMLInclude - but it's not been updated in 7 years, leaving questions. I'll try yours and theirs in due course. Err, and the fragment @HumanOstrich said elsewhere in comments.

Re: Why can't HTML alone do includes?

#273
post #77

Netscape 4 has this with inflow layers — ` ` https://web.archive.org/web/19970630074729fw_/http://develop... https://web.archive.org/web/19970630094813fw_/http://develop...

As far as I'm aware of it, changing the SRC-attribute was quite crash-y and the functionality was stripped soon. (I remember playing with this in beta, and then it was gone in the production version.)

Re: Why can't HTML alone do includes?

#274
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…

I've become a fan of https://htmx.org for this reason. A small 10KB lib that augments HTML with the essential good stuff (like dynamic imports of static HTML)

The minified version needs ~51 kilobytes (16 compressed):

  $ curl --location --silent "https://unpkg.com/htmx.org@2.0.4" | wc -c
  50917
  
  $ curl --location --silent "https://unpkg.com/htmx.org@2.0.4" | gzip --best --stdout | wc -c
  16314

Re: Why can't HTML alone do includes?

#275

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…

Me personally, I didn't even care that much about strict semantic web, but XML has the benefits of the entire ecosystem around it (like XPath and XSLT), composable extensibility in form of namespaces etc. It was very frustrating to see all that thrown out with HTML5, and the reasoning never made any sense to me (backwards compatibility with pre-XHTML pages would be best handled by defining a spec according to which t…

If XHTML was literally just HTML but with XML syntax, it would be pretty cool.

Re: Why can't HTML alone do includes?

#276
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.)

Re: Why can't HTML alone do includes?

#277

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'm as big a critic of Google as anyone, but I'm always surprised at modern day takes around the lost semantic web technologies - they are missing facts or jumping to conclusions in hindsight. Here's what people should know. 1) The failure of XHTML was very much a multi-vendor, industry-wide affair; the problem was that the syntax of XML was stricter than the syntax of HTML, and the web was already littered with brok…

Point n°2 is only partially correct.

Google does support multiple semantic web standards: RDFa, JSON+LD and I believe microdata as well.

JSON+LD is much simpler to extract and parse, however it makes site HTML bigger because information gets duplicated compared to RDFa where values could be inclined.

Re: Why can't HTML alone do includes?

#278

Earlier quoted context omitted.

What bug specifically?

Couldn't find a good link earlier, guess I didn't have quite the right keywords for search. Here we go, looks like its 17 years old now: https://bugzilla.mozilla.org/show_bug.cgi?id=98168#c99

This bug is specifically about not working in Firefox. How is disabling output escaping relevant in regards to sharing templates between pages?

Re: Why can't HTML alone do includes?

#280

I'm not an expert on this but IMO, from a language point of view, HTML is a markup language, it 'must' have no logic or processing. It is there to structure the information not to dynamically change it. Nor even to display it nicely. The logic is performed elsewhere. If you were to have includes directly in HTML, it means that browsers must implement logic for HTML. So it is not 'just' a parser anymore. Imagine for e…

I feel like most of your answer is invalidated by

* the actual existence of frames (although those are deprecated)

* iframes (which are not deprecated, so seemingly doing declarative inclusion of HTML in HTML was not what was wrong with frames)

* imports in CSS, which share some of the same problems / concerns as HTML imports

* the existence of JavaScript with its ability to change anything on the page, including the ability to issue HTTP requests and be written arbitrarily obfuscated ways.

Post reply on HN