Live data from Hacker News

Why can't HTML alone do includes?

frontendmasters.com

181–190 of 367 posts

Re: Why can't HTML alone do includes?

#181
post #155

Earlier quoted context omitted.

you need a server for HTML to work, as practical matter. But yes. There IS a workaround to that too, if you're REALLY determined, but you have to format your HTML a giant JS comment block (lol really :)) [edit: I'm sure there are still some file:// workflows for docs - and yes this doesn't address that]

You don't need a server for HTML to work, I can just hand you a USB stick/floppy disk/MO disk for your NeXT with HTML files on it.

( •_•) ( •_•)>⌐■-■ (⌐■_■) Deal with it.

:)

Re: Why can't HTML alone do includes?

#182
post #176

This is the closest we can do today: -- index.html Hello includes -- header.js document.currentScript.outerHTML = ` Header ` -- footer.js document.currentScript.outerHTML = ` Footer ` Scripts will replace their tags with html producing a clean source, not pretty but it works on the client

Pretty sure it is possible without JavaScript, too.

Re: Why can't HTML alone do includes?

#183

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.

We also had a brief detour into XML with XHTML, and XML has XInclude, although it's not a required feature.

Re: Why can't HTML alone do includes?

#184

Earlier quoted context omitted.

HTML is a markup language, not a programming language. It's like asking why Markdown can't handle includes. Some Markdown editors support them (just like some server-side tools do for HTML), but not all.

I think this is the most likely answer. I'm not defending it, because when I started web development this was one of the first problems I ran into as well -- how the heck do you include a common header. But the original concept of HTML was standalone documents, not websites with reusable components like headers and footers and navbars. That being said, I still don't understand why then the frames monstrosity was inve…

The original concept of HTML was as an SGML subset, and SGML had this functionality, precisely because it's very handy for document authoring to be able to share common snippets.

Re: Why can't HTML alone do includes?

#185

There are all kind of issues with HTML include as others have pointed out If main.html includes child/include1.html and child/include1.html has a link src="include2.html" then when the user clicks the link where does it go? If it goes to "include2.html", which by the name was meant to be included , then that page is going to be missing everything else. If it goes to main.html, how does it specify this time, use inclu…

These are all solvable issues with fairly obvious solutions. For example:

> If main.html includes child/include1.html and child/include1.html has a link src="include2.html" then when the user clicks the link where does it go? If it goes to "include2.html", which by the name was meant to be included, then that page is going to be missing everything else. If it goes to main.html, how does it specify this time, use include2.html, not include1.html?

There are two distinct use cases here: snippet reuse and embeddable self-contained islands. But the latter is already handled by iframes (the behavior being your latter case). So we only need to do the former.

Re: Why can't HTML alone do includes?

#186
post #97

Earlier quoted context omitted.

That’s the Hyper part of HTML, and what makes it special. It’s made to pull in external resources (as opposed to other document formats like PDF). Scripts, stylesheets, images, objects, favicons, etc. HTML is thematically similar.

No, HTML is fundamentally different because (for a static site without any JS dom manipulation) it has all the semantic content, while stylesheets, images, objects, etc. are just about presentation.

Images are content. Videos are content. Objects/iframes are content.

The only one that is presentational is stylesheets.

Re: Why can't HTML alone do includes?

#187

Earlier quoted context omitted.

Well said this is many students' intro to PHP. Why not ` ` though? Some content is already loaded asynchronously such as images, content below the fold etc. > HTML is really just a markup syntax, not a programming language flamebait detected :) It's a declarative language, interpreted by each browser engine separately.

What's the ML in HTML stand for? I think that's probably the crux of the argument. Are we gonna evolve it past its name?

It stands for "markup language", and was inherited from SGML, which had includes. Strictly speaking, so did early HTML (since it was just an SGML subset), it's just that browsers didn't bother implementing it, for the most part. So it's not that it didn't evolve, but rather it devolved.

Nor is this something unique to SGML. XML is also a "markup language", yet XInclude is a thing.

Re: Why can't HTML alone do includes?

#188

Earlier quoted context omitted.

Yep, and this can be used to e.g. make a basically static site template and then do an include for `userdata.xml` to decorate your page with the logged in user's info (e.g. on HN, adding your username in the top right, highlighting your comments and showing the edit/delete buttons, etc.). You can for example include into a variable ` ` and then use it in xpath expressions like `$myinfo/user/@id`. Extremely simple, go…

> I will never understand why it didn't take off. I’ve used XSLT in anger - I used it to build Excel worksheets (in XML format) using libXSLT. I found it very verbose and hard to read. And Xpath is pretty torturous. I wish I could have used Javascript. I wish Office objects were halfway as easy to compose as the DOM. I know a lot of people hate on Javascript and the DOM, but it’s way easier to work with than the alte…

XQuery is basically XSLT with saner syntax.

Re: Why can't HTML alone do includes?

#189

Earlier quoted context omitted.

it is mentioned in the article indeed; it's an awful solution that is poor in performance and break the accessibility

Why would the performance be any better with another tag?

A frame is a separate rendering context—it's (almost) as heavyweight as a new tab. The author wants to insert content from another file directly into the existing DOM, merging the two documents completely.

Re: Why can't HTML alone do includes?

#190
post #137

You can get JS-free, client-side include functionality if you're willing to wrap your HTML in XML. Here is a demo: https://github.com/Evidlo/xsl-website

I don't think you even need to wrap it, really. You need to make sure it's valid XML, but the root element could be just fine. And then use an identity transform with .
Post reply on HN