16 ms·
Why can't HTML alone do includes?
- paulryanrogers 1y agoHTML does have frames and iframes, which can accomplish some of the same goals.
- hollowturtle 1y agoit is mentioned in the article indeed; it's an awful solution that is poor in performance and break the accessibility
- mixmastamyk 1y agoWhy would the performance be any better with another tag?
- rhet0rica 1y agoA 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.
- mixmastamyk 1y agoNegligible twenty years ago. But yes, if there's an improvement it should be merged automatically into the same document.
- paulryanrogers 1y agoThanks. I was reading too fast and missed the iframe reference in the article
- dinkblam 1y agowe had no problem using <object> for headers and footers
- bandrami 1y agoBecause how would the browser decide it's in a fetch loop?
- axelfontaine 1y agoIframes, while not perfect, are pretty close though...
- lelandfe 1y agoMaking iframes be the right size is super awkward. I might actually use them more if they were easy to get responsive. This post does link to a technique (new to me) to extract iframe contents: <iframe src="/example.html" onload="this.before((this.contentDocument.body||this.contentDocument).children[0]);this.remove()"></iframe>
- dleeftink 1y agoI've come across this technique here [0] to try it on <object> elements, but sizing is even more difficult there. [0]: https://www.filamentgroup.com/lab/html-includes/ https://www.filamentgroup.com/lab/html-includes/
- cratermoon 1y agoAre we solving the information-centric transclusion problem, or the design-centric asset reuse problem? An iframe is fine for the former but is not geared towards design and layout solutions.
- lelandfe 1y agoIt kinda sucks for both! Dropping in a box of text that flatly does not resize to fit its contents does not fit the definition of "fine" for me, here. You can do some really silly maneuvers with `window.postMessage` to communicate an expected size between the parent and frame on resize, but that's expensive and fiddly.
- rendaw 1y agoInteraction between elements in different iframes is very restricted.
- 1y ago
- evrimoztamur 1y agoIf you want to include HTML sandboxes, we have iframes. If you want it served from the server, it's just text. Putting text A inside text B is a solved problem.
- zamadatix 1y agoThe article references both of these methods with explanations of why they don't feel they answer the question posed.
- esperent 1y ago> Putting text A inside text B is a solved problem. Yes, but in regards to HTML it hasn't been solved in a standard way, it's been solved in hundreds, if not thousands of non standard ways. The point of the article is that having one standard way wlcould reduce a lot of complexity from the ecosystem, as ES6 imports did.
- bdcravens 1y agoThe simplest answer is that HTML wasn't designed as a presentation language, but a hypertext document language. CSS and Javascripts were add-ons after the fact. Images weren't even in the first version. Once usage of the web grew beyond the initial vision, solutions like server-side includes and server-side languages that rendered HTML were sufficient.
- skydhash 1y agoI think the best examples of HTML in that regard is HTML-rendered info pages[0], for Emacs and its ecosystem. Then you have the same content presented in HTML [1]. Templates were enough in the first case. Includes are better in the second case due to common assets external to the content. [0]: https://www.gnu.org/software/emacs/manual/html_node/emacs/index.html https://www.gnu.org/software/emacs/manual/html_node/emacs/in... [1]: https://emacsdocs.org/docs/emacs/The-Emacs-Editor https://emacsdocs.org/docs/emacs/The-Emacs-Editor
- nico 1y agoFTA > We’ve got <iframe>, which technically is a pure HTML solution, but And then on the following paragraph.. > But none of the solutions is HTML > None of these are a straightforward HTML tag Not sure what the point is. Maybe just complaining
- pjc50 1y agoIframe is stuck in a rectangular box. It's not really suitable for things like site wide headers, footers and menus.
- vlovich123 1y agoWhile I get your point, headers and footers and menus tend to all live within rectangular boxes.
- zamadatix 1y agoHeaders and their menus are often problematic for this approach, unless they are 100% static (e.g. HN would work but Reddit and Google wouldn't since they both put things in their header which can expand over the content). I.e. you can make it transparent but that doesn't solve eating the interactions. The code needed to work around that is more than just using JS to do the imports.
- teg4n_ 1y agoDo a drop down list of links on a header in an iframe
- jefftk 1y agoHeaders and footers, yes. Menus generally need to expand when you interact with them, especially on mobile.
- ComplexSystems 1y ago<iframe> is different from what the author is asking for, it has its own DOM and etc. He wants something like an SSI but client side. He explains some of the problems right after the part you cut off above "We’ve got <iframe>, which technically is a pure HTML solution, but they are bad for overall performance, accessibility, and generally extremely awkward here"
- tln 1y agoThere used to be a thing for this https://caniuse.com/imports https://caniuse.com/imports
- tehbeard 1y agoNo HTML imports was an idea of using the HTML document format to encapsulate the 3 distinct data types needed for custom elements: - JS for functionality via the custom elements API - HTML for layout via <template> tags. - CSS for aesthetics via <style> tags. Not for just quickly and simply inserting the contents of header.html at a specific location in the DOM.
- HeavyStorm 1y agoSays "superseded by ES modules". Not really the same thing, right?
- tln 1y agoThe article asks about includes but also about imports ("HTML cannot import HTML ") which this is very directly. This feature was billed as #includes for the web [1]. No, it acts nothing like an #include. TBH I don't see why ES modules are a "replacement" here. Personally I would like to see something like these imports come back, as a way to reuse HTML structure across pages, BUT purely declaratively (no JS needed). #includes where partially formed HTML (ie, header.html has a <body> open tag and footer.html has the closing tag) isn't very DOM compatible. [1] https://web.archive.org/web/20181121181125/https://www.html5rocks.com/en/tutorials/webcomponents/imports/ https://web.archive.org/web/20181121181125/https://www.html5...
- moffkalast 1y agoChad QQ and UC browsers, the only ones still supporting HTML imports lmao. I've never heard of them before but I like the cut of their jib.
- hilti 1y agoHave you ever heard of Server Side Includes? https://en.wikipedia.org/wiki/Server_Side_Includes https://en.wikipedia.org/wiki/Server_Side_Includes
- rendaw 1y agoThat's mentioned in TFA under "old school web server directives".
- deleted 1y ago[deleted]
- rsolva 1y agoAfter researching this very topic earlier; SSI is the most pragmatic solution. Check out Caddy's Template Language (based on Go), it is quite capable and quite similar to building themes in Hugo. Just much more bare bones. I have built several sites with pure HTML+CSS, sprinkled with some light SSI with Caddy, and it is rock solid and very performant!
- DJHenk 1y agoMy guess: no-one needs it. Originally, iframe were the solution, like the posts mentions. By the time iframes became unfashionable, nobody was writing HTML with their bare hands anymore. Since then, people use a myriad of other tools and, as also mentioned, they all have a way to fix this. So the only group who would benefit from a better iframe is the group of people who don't use any tools and write their HTML with their bare hands in 2025. That is an astonishing small group. Even if you use a script to convert markdown files to blog posts, you already fall outside of it. No-one needs it, so the iframe does not get reinvented.
- micromacrofoot 1y agowhat if it could be a larger group though? modern css has been advancing rather rapidly... I don't even need a preprocessing library any more... I've got nested rules, variables, even some light data handling... why not start beefing up html too? we've got some new features but includes would be killer
- Svip 1y agoNo, originally frameset[0] and frame[1] were the solution to this problem. I remember building a website in the late 1990s with frameset. iframe came later, and basically allowed you to do frames without the frameset. Anyway, frameset is also the reason every browser's user agent starts with "Mozilla". [0] https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/frameset https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/... [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/frame https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...
- chgs 1y agoOriginally my footers and navbars were included with server side includes
- dimal 1y agoThis 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 over in different ways. For those saying that iframes are good enough, they’re not. Iframes don’t expand to fit content. And server side solutions require a server. Why not have a simple client side method for this? I think it’s a valid question. Now that we’re fixing a lot of the irritation in web development, it seems worth considering.
- econ 1y agoYou can message the page dimensions to the parent. To do it x domain you can load the same url into the parent with the height in the #location hash. It won't refresh that way.
- dimal 1y agoI know it’s possible to work around it, but that’s not the point. This is such a common use case that it seems worthwhile to pave the cowpath. We’ve paved a lot of cowpaths that are far less trodden than this one. This is practically a cow superhighway. We’ve built an industry around solving this problem. What if, for some basic web publishing use cases, we could replace a complex web framework with one new tag?
- econ 1y agoI couldn't agree more. <div src="foo.txt"></div>
- wizzwizz4 1y agohttps://www.w3.org/TR/xhtml2/introduction.html https://www.w3.org/TR/xhtml2/introduction.html > XHTML 2 takes a completely different approach, by taking the premise that all images have a long description and treating the image and the text as equivalents. In XHTML 2 any element may have a @src attribute, which specifies a resource (such as an image) to load instead of the element.
- jasoncartwright 1y agoI made this to get around pages being cached at CDN level, but still needing to get live data... https://github.com/jasoncartwright/clientsideinclude https://github.com/jasoncartwright/clientsideinclude
- Imustaskforhelp 1y agoI think this is a genuinely good question that I was also wondering some time ago. And it is a genuinely good question! I think the answer of PD says feels the truest. JS/CSS with all its bureaucracy are nothing compared to HTML it seems. Maybe people don't find nothing wrong with Html, maybe if they do, they just reach out for js/css and try to fix html (ahem frontend frameworks). That being said, I have just regurgitated what PD says has said and I give him full credit of that but I am also genuinely confused as to why I have heard that JS / CSS are bureaucratic (I remember that there was this fireship video of types being added in JS and I think I had watched it atleast 1 year ago (can be wrong) but I haven't heard anything for it and I see a lot of JS proposals just stuck from my observation And yet HTML is such level of bureaucratic that the answer to why HTML doesn't have a feature is because of its bureaucracy. Maybe someone can explain the history of it and why?
- SJC_Hacker 1y agoInitially HTML was less about the presentation layer and more about the "document" concept. Documents should be self-contained, outside of references to other documents.
- skydhash 1y agoI still think this is the best web. Either you are a collection of interlinked documents and forms (manual pages, wiki,...), or you are a full application (figma, gmail, google docs). But a lot of sites are trying to be both. And somes are trying to be one while they are the other type.
- spauldo 1y agoOne 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?
- mmastrac 1y agoDo remote entity references still work in XHTML? XML had its issues but did have a decent toolbox of powerful if not insecure primitives.
- rs186 1y agoI guess for the similar reason that Markdown does not have any "include" ability -- it is a feature not useful enough yet with too many issues to deal with. They are really intended to be used as "single" documents.
- rs186 1y agoYeah people downvote me but can't bother to leave a comment. If you disagree, and you think you are in the right, you probably have a somewhat good argument you can use in a reply. The fact that you don't means my explanation makes sense.
- KingLancelot 1y ago[dead]
- uallo 1y agoThere is an open issue about this at WHATWG (also mentioned in the comment section of the blog post): Client side include feature for HTML https://github.com/whatwg/html/issues/2791 https://github.com/whatwg/html/issues/2791
- bambax 1y ago> We’ve got <iframe>, which technically is a pure HTML solution, but they are bad for overall performance, accessibility, and generally extremely awkward here What does this mean? This is a pure HTML solution, not just "technically" but in reality. (And before iframe there were frames and frameset). Just because the author doesn't like them don't make them non-existent.
- ajkjk 1y agoNo way. You can't make a decent single web page by iframing a bunch of components together.
- jadamson 1y agoWhat do you mean what does it mean? An iframe is a window into another webpage, and is bounded as such both visually and in terms of DOM interfaces. A simple example would be that an iframe header can't have drop-down menus that overlap content from the page hosting it. They are categorically not the same DX/UX as SSI et al. and it's absolutely bizarre to me that there's so many comments making this complaint.
- silvestrov 1y agoThe real problem with iframes is that their size is set by the parent document only. They would be a lot more useful if we could write e.g. <iframe src=abc.html height=auto width=100> so the height of the iframe element is set by the abc.html document instead of the parent document.
- baggy_trough 1y agoYou can achieve that with js in the parent document.
- teg4n_ 1y agoYou can achieve everything with JS in the parent document, it doesn’t mean it should be required or even recommended
- rchaud 1y ago"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. There really isn't any need to make includes available through just HTML. HTML is a presentation format and doesn't do anything interesting without CSS and JS anyway.
- assimpleaspossi 1y agoAgree with what you said, however, HTML is a document description language and not a presentation format. CSS is for presentation (assuming you meant styling).
- PaulDavisThe1st 1y agoThey didn't mean styling. HTML is a markup language that identifies the functional role of bits of text. In that sense, it is there to provide information about how to present the text, and is thus a presentation format. It is also a document description language, because almost all document description languages are also a presentation format.
- cantSpellSober 1y agoWell said this is many students' intro to PHP. Why not `<include src=header.html/>` 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.
- gyesxnuibh 1y agoWhat'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?
- Linux-Fan 1y agoIsn't this what proper framesets (not iframes) were supposed to do a long time ago (HTML 4?). At least they autoexpanded just fine and the user could even adjust the size to their preference. There was a lot of criticism for frames [1] but still they were successfully deployed for useful stuff like Java API documentation [2]. In my opinion the whole thing didn't stay mostly because of too little flexibility for designer: Framesets were probably well enough for useful information pages but didn't account for all the designers' needs with their bulky scrollbars and limited number of subspaces on the screen. Today it is too late to revive them because framesets as-is wouldn't probably work well on mobile... [1] <https://www.nngroup.com/articles/why-frames-suck-most-of-the-time/ https://www.nngroup.com/articles/why-frames-suck-most-of-the...> - I love how much of it is not applicable anymore and all of these problems mentioned with frames are present in today's web in an even nastier way? [2] <https://www.eeng.dcu.ie/~ee553/ee402notes/html/figures/JavaDocCapture.gif https://www.eeng.dcu.ie/~ee553/ee402notes/html/figures/JavaD...>
- johannes1234321 1y agoIssue with frame set was way more fundamental: No deep linking, thus people coming via bookmarks or Google (or predecessor) were left on a page without navigation, which people then tried working around with JavaScript, which never gave it a good experience.
- Linux-Fan 1y agoNowdays it is sometimes the other way around: Pages are all JavaScript so no good experience in the first place. I have encountered difficulty trying to get a proper “link” to something multiple times. Also, given that Browsers love to reduce/hide the address bar I wonder if it is really still that important a feature. Of course "back then" this was an important feature and one of the reasons for getting rid of frames :)
- austin-cheney 1y agoSo, HTML did have includes and they fell out of favor. The actual term include is an XML feature and it’s that feature the article is hoping for. HTML had an alternate approach that came into existence before XML. That approach was frames. Frames did much more than XML includes and so HTML never gained that feature. Frames lost favor due to misuse, security, accessibility, and variety of other concerns.
- Linux-Fan 1y agoUnlike Framesets I think XML includes were never really supported in many browsers (or even any major browsers)? I still like to use them occasionally but it incurs a "compilation" step to evaluate them prior to handing the result of this compilation to the users/browsers.
- LegionMammal978 1y agoAs it happens, the major browsers still can do XML 'includes' to some extent, since by some miracle they haven't torn out their support for XSLT 1.0. E.g. this outputs "FizzBuzz" on Firefox: <!-- fizz.xml --> <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="application/xslt+xml" href="style.xslt"?> <fizz>Fizz<buzz/></fizz> <!-- style.xslt --> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="buzz"> <xsl:value-of select="document('buzz.xml')"/> </xsl:template> </xsl:stylesheet> <!-- buzz.xml --> <?xml version="1.0" encoding="UTF-8"?> <buzz>Buzz</buzz> You can even use XSLT for HTML5 output, if you're careful. But YMMV with which XML processors will support stylesheets.
- ndriscoll 1y agoYep, 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 `<xsl:variable name="myinfo" select="document('userdata.xml')"/>` and then use it in xpath expressions like `$myinfo/user/@id`. Extremely simple, good for caching, lightweight, very high performance. Easy to fail gracefully to the logged out template. You basically get your data "API" for free since you're returning XML in your data model. I will never understand why it didn't take off. XML includes are blocking because XSL support hasn't been updated for 25 years, but there's no reason why we couldn't have it async by now if resources were devoted to this instead of webusb etc.
- johannes1234321 1y agoI would guess back in the days having extra requests was expensive, thus discouraged. Later there were attempts via xinclude, but by then PHP and similar took over or people tolerated frames.
- somethingsome 1y agoI'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 example that I create an infinite loop of includes, who is responsible to limit me? How to ensure that all other browsers implement it in the same way? What happens if I perform an injection from another website? Then we start to have cors policy management to write. (iframes were bad for this) Now imagine using Javascript I inject an include somewhere, should the website reload in some way? So we have a dynamic DOM in HTML?
- naasking 1y ago> from a language point of view, HTML is a markup language, it 'must' have no logic or processing. Client-side includes are not "processing". HTML already has frames and iframes which do this, just in a worse way, so we'd be better off.
- somethingsome 1y agoI understand your point, but I still think it is bad from the point of view of language paradigms[1]. Iframes should have not been created in the first place.. You are changing the purpose of the language while it was not made for it. (yes in my view I interpret includes as a basic procedure) [1] http://www.info.ucl.ac.be/people/PVR/paradigmsDIAGRAMeng201.pdf http://www.info.ucl.ac.be/people/PVR/paradigmsDIAGRAMeng201....
- naasking 1y agoThere is nothing procedural about includes. In fact, it first appeared before HTML even became popular in Xanadu, called transclusion: https://en.wikipedia.org/wiki/Transclusion https://en.wikipedia.org/wiki/Transclusion
- lenkite 1y ago
- Null-Set 1y agoThe name of this feature is transclusion. https://en.wikipedia.org/wiki/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.
- jes5199 1y agoWard 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 https://en.wikipedia.org/wiki/Federated_Wiki it never quite took off
- PaulHoule 1y agoI think true transclusion would be more than that. In Xanadu you could transclude just an excerpt from one document into another document. If you wanted to do this with HTML you need an answer for the CSS. In any particular case you can solve it, making judgements about which attributes should be consistent between the host document, the guest document and the guest-embedded-in-host. The general case, however, is unclear. For a straightforward <include ...> tag the guest document is engineered to live inside the CSS environment (descendant of the 3rd div child of a p that has class ".rodney") that the host puts it in. Another straightforward answer is the Shadow DOM which, for the most part, lets the guest style itself without affecting the rest of the document. I think in that case the host can still put some styles in to patch the guest.
- bufferoverflow 1y agoiframe is html
- esprehn 1y agoWe discussed this back when creating web components, but the focus quickly became about SPA applications instead of MPAs and the demand for features like this was low in that space. I wish I would have advocated more for it though. I think it would be pretty easy to add using a new attribute on <script> since the parser already pauses there, so making something like <script transclude={url}> would likely not be too difficult.
- prkl 1y agohonestly, html can include css and javascript via link and style tags. there's no reason for it to not have an <include src="" /> tag, and let the browser parsing it fetch the content to replace it.
- _heimdall 1y agoIf I really need HTML includes for some reason, I'd reach for XSLT. I know its old, and barely maintained at best, but that was the layer intentionally added to add programming language features to the markup language that is HTML.
- mark_and_sweep 1y agoI believe XSLT 1 is still working in all major browsers today. Here's a simple HTML 5 example with two pages sharing a header template: https://gist.github.com/MarkTiedemann/0e6d36c337159a3e6d5072ccb7d7f6fe https://gist.github.com/MarkTiedemann/0e6d36c337159a3e6d5072...
- _heimdall 1y agoMy main gripe is a decade(s?) old Firefox bug related to rendering an HTML string to the DOM. That may be a fairly specific use case though, and largely it still works great today. I've done a few side projects with XSLT and web components for interactivity, worked great.
- mark_and_sweep 1y agoWhat bug specifically?
- _heimdall 1y agoCouldn'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 https://bugzilla.mozilla.org/show_bug.cgi?id=98168#c99
- DemocracyFTW2 1y agofrom the linked thread: > The only combination that fails to render these entities correctly is Firefox/XSLT. Which is one good reason not to adopt XSLT to implement HTML includes. You just don't know what snags you'll hit upon but you can be sure you'll be on your own. > Bug 98168 (doe) Opened 24 years ago Updated 21 days ago Well it does look like someone's still mulling over whether and how to fix it... 24 years later...
- hyperhello 1y agoI think it’s because it would be so easy to make a recursive page that includes itself forever. So you have to have rules when it’s okay, and that’s more complex and opaque than just programming it yourself.
- ludwik 1y agoWe used to have this in the form of a pair of HTML tags: <frameset> and <frame> (not to be confused with the totally separate <iframe>!). <frameset> provided the scaffolding with slots for multiple frames, letting you easily create a page made up entirely of subpages. It was once popular and, in many ways, worked quite neatly. It let you define static elements once entirely client-side (and without JS!), and reload only the necessary parts of the page - long before AJAX was a thing. You could even update multiple frames at once when needed. From what I remember, the main problem was that it broke URLs: you could only link to the initial state of the page, and navigating around the site wouldn't update the address bar - so deep linking wasn’t possible (early JavaScript SPA frameworks had the same issue, BTW). Another related problem was that each subframe had to be a full HTML document, so they did have their own individual URLs. These would get indexed by search engines, and users could end up on isolated subframe documents without the surrounding context the site creator intended - like just the footer, or the article content without any navigation.
- throwup238 1y agoThe feature proposal was called HTML Imports [1], created as part of the Web Components effort. > HTML Imports are a way to include and reuse HTML documents in other HTML documents There were plans for <template> tag support and everything. If I remember correctly, Google implemented the proposed spec in Blink but everyone else balked for various reasons. Mozilla was concerned with the complexity of the implementation and its security implications, as well as the overlap with ES6 modules. Without vendor support, the proposal was officially discontinued. [1] https://www.w3.org/TR/html-imports/ https://www.w3.org/TR/html-imports/
- riedel 1y agohttps://caniuse.com/imports https://caniuse.com/imports says FF even had it as a config flag
- AtlasBarfed 1y agoFrames essentially could do html import
- xg15 1y agoThat matches with the comment [1] on the article, citing insufficient demand, no vendor enthusiasm, etc. The thing is that all those are non-reasons that don't really explain anything: Low demand is hard to believe if this feature is requested for 20 years straight and there are all kinds of shim implementations using scripts, backend engines, etc. (And low demand didn't stop other features that the vendors were interested in for their own reasons) Vendor refusal also doesn't explain why they refused it, even to the point of rolling back implementations that already existed. So I'd be interested to understand the "various reasons" in more detail. "Security implications" also seem odd as you already are perfectly able to import HTML cross origin using script tags. Why is importing a script that does document.write() fine, but a HTML tag that does exactly the same thing hugely problematic? (I understand the security concern that you wouldn't want to allow something like "<import src=google.com>" and get an instant clone of the Google homepage. But that issue seems trivially solvable with CORS.) [1] https://frontendmasters.com/blog/seeking-an-answer-why-cant-html-alone-do-includes/#comment-26756 https://frontendmasters.com/blog/seeking-an-answer-why-cant-...
- djoldman 1y ago> Our developer brains scream at us to ensure that we’re not copying the exact code three times, we’re creating the header once then “including” it on the three (or a thousand) other pages. Interesting, my brain is not this way: I want to send a minimum number of files per link requested. I don't care if I include the same text because the web is generally slow and it's generally caused by a zillion files sent and a ton of JS.
- drob518 1y agoSeems like this would help with caching, too.
- Lammy 1y agoNetscape 4 has this with inflow layers — `<ILAYER SRC=included.html></ILAYER>` https://web.archive.org/web/19970630074729fw_/http://developer.netscape.com/library/documentation/communicator/dynhtml/layers32.htm#1016983 https://web.archive.org/web/19970630074729fw_/http://develop... https://web.archive.org/web/19970630094813fw_/http://developer.netscape.com/library/documentation/communicator/dynhtml/layers33.htm#1016318 https://web.archive.org/web/19970630094813fw_/http://develop...
- typedef_struct 1y agoYou 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.response this.replaceWith(document) }).bind(this)) fetch.open('GET', href) fetch.send() } })
- 1718627440 1y agoThis 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 combined two already packed and annotated documents of nodes. So I would say it is more due a semantic meaning. I think there was also the idea of requesting arbitrary sets of nodes, but that was never developed and with the shift away from a semantic document, it didn't make sense anymore.
- gugagore 1y agoI think the quickest way to say it is that there is only one head on a page, and every HTML file needs a head. So if you include one into the other, you either have two heads, or the inner document didn't have a head.
- mattlondon 1y agoSee DofumentFragment - sounds a lot like this: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment https://developer.mozilla.org/en-US/docs/Web/API/DocumentFra...
- econ 1y agoThey can just be html chunks. No need to make sense on their own. Maybe a single tag that points at an url to load if someone attempts to load the chunk directly.
- mr_toad 1y ago> 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.
- 1718627440 1y agoI 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.
- tiku 1y agoiFrames have a src and includes other html.. We used to make sites with it way back.
- sreekotay 1y agoThis has always worked for me. Pretty much the ask? https://gist.github.com/sreekotay/08f9dfcd7553abb8f1bb17375d601633 https://gist.github.com/sreekotay/08f9dfcd7553abb8f1bb17375d...
- alecsm 1y agoBut you need a server for that to work.
- sreekotay 1y agoyou 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]
- CamouflagedKiwi 1y agoThat's the first thing listed in the article? "Javascript to go fetch the HTML and insert it". What they're after is something that's _just_ HTML and not another language.
- sreekotay 1y agoWhile you do need a server i think this is the functional equivalent? The fetch JS and insert outlined (linked to) in the article is async. This blocks execution like you'd expect an HTML include to do. It's WAY easier to reason about - which is why the initial ask, I think...
- jsdwarf 1y agoI'd say in 80% of the cases a pure, static html include is not enough. In a menu include, you want to disable the link to the currently shown page or show a page specific breadcrumb. In a footer include, you may want a dynamic "last updated" timestamp or the current year in the copyright notice. As all these use cases required a server-side scripting language anyway, there was no push behind an html include.
- perilunar 1y ago> In a menu include, you want to disable the link to the currently shown page I’ve always just styled the link to the current page differently, not disabled it, which you can do with an id on the page and a line of CSS.
- steren 1y agoin the meantime, you can use <html-include> https://www.npmjs.com/package/html-include-element https://www.npmjs.com/package/html-include-element
- franze 1y agoNow you can include HTML in HTML, see https://include.franzai.com/ https://include.franzai.com/ - a quick Chrome Polyfill based on the discussion here. MIT License Github: https://github.com/franzenzenhofer/html-include-polyfill-extension/ https://github.com/franzenzenhofer/html-include-polyfill-ext... SHOW HN: https://news.ycombinator.com/item?id=43881815 https://news.ycombinator.com/item?id=43881815
- neuroelectron 1y agoSo 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.
- spauldo 1y agoYou 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.
- kyledrake 1y agoAt least some of the blame here is the bias towards HTML being something that is dynamic code generated, as opposed to something that is statically handwritten by many people. There are features that would be good for the latter that have been removed. For example, if you need to embed HTML code examples, you can use the <xmp> tag, which makes it so you don't need to encode escapes. Sadly, the HTML5 spec is trying to obsolete the <xmp> tag even though it's the only way to make this work. All browsers seem to be supporting it anyways, but once it is removed you will always have to encode the examples. HTML spec developers should be more careful to consider people hand coding HTML when designing specifications, or at least decisions that will require JavaScript to accomplish something it probably shouldn't be needed for.
- TZubiri 1y agoIt's the other way around, HTML was designed to be hand written, and the feature set was defined at that stage. If it ended up being dynamically generated, that happened after the feature set was defined.
- kmoser 1y agoSHTML used to be a thing back in the 1990s: https://en.wiktionary.org/wiki/SHTML https://en.wiktionary.org/wiki/SHTML
- Telemakhos 1y agoOr, better, "Server Side Includes" (SSI): https://en.wikipedia.org/wiki/Server_Side_Includes https://en.wikipedia.org/wiki/Server_Side_Includes SSI is still a thing: I use it on my personal website. It isn't really part of the HTML, though: it's a server-dependent extension to HTML. It's supported by Apache and nginx, but not by every server, so you have to have control over the server stack, not just access to the documents.
- TZubiri 1y agoBecause it's HyperText, the main idea is that you link to other content, so this is not a weird feature that is being asked for, it's just a different way of doing the whole raison d'etre of the tech. In fact the tag to link stuff is the <a> tag. It just so happens that it makes you load the other "page", instead of transcluding content, the idea is that you load it. It wouldn't make sense to transclude the article about the United States in the article about Wyoming (and in fact modern wikipedia shows a pop up bubble doing a partial transclusion, but would benefit in no way from basic html transclusion.) It's a simple idea. But of course modern HTML is not at all what HTML was designed to be, but that's the canonical answer. The elders of HTML would just tell you to make an <a> link to whatever you wanted to transclude instead. Be it a "footer/header/table of contents" or another encylcopdic article, or whatever. Because that's how HTML works, and not the way you suggest. Think of what would happen if it were the case, you would transclude page A, which transcludes page B, and so with page C, possibly recursively transcluding page B and so. You would transform the User Agent (browser) into a whole WWW crawler! It's because HTML is pass by reference, not pass by copy.
- Evidlo 1y agoYou 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 https://github.com/Evidlo/xsl-website
- imiric 1y agoThat's interesting, thanks. How well supported is XSLT in modern browsers? What would be the drawbacks of using this approach for a modern website?
- Evidlo 1y agoIts fully supported in every current browser. Some things that suck are that XML is stricter than HTML and every XML needs to include the templates file at the first line
- int_19h 1y agoI 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 <html> just fine. And then use an identity transform with <xsl:output method="html">.
- miragecraft 1y agoI 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 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 include be done synchronously or asynchronously? The big benefit of traditional server side includes is that its synchronous, thus simplifying logic for in-page JavaScript, but all browsers are trying to eliminate synchronous calls for speed, it’s hard to see them agreeing to add a new synchronous bottleneck. Should it be CORS restricted? If it is then it blocks offline use (file:// protocol) which really kills its utility. There are a lot of hurdles to it and it’s hard to get people to agree on the exact implementation, it might be best to leave it to JavaScript libraries.
- paul_h 1y agoSomeone else made the same - https://github.com/Paul-Browne/HTMLInclude 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.
- DemocracyFTW2 1y agoMy 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 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.
- dwheeler 1y agoHTML 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. <!DOCTYPE html example [ <!ENTITY myheader SYSTEM "myheader.html"> ]> .... &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.
- lkuty 1y agoIt existed also in DTD (Document Type Definition) used with HTML 4 and below, and XML. Came fromn SGML too I guess.
- tannhaeuser 1y agoYes 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 https://sgmljs.net/docs/html5.html [2]: https://sgmljs.net/blog/blog2303.html https://sgmljs.net/blog/blog2303.html
- int_19h 1y agoWe also had a brief detour into XML with XHTML, and XML has XInclude, although it's not a required feature.
- echelon 1y agoIt'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 of tooling. Google / WhatWG wanted easy to author pages (~="sloppy markup, nonstandard docs") because nobody else could "organize the web" like them if it was disorganized by default. Once the late 2010's came to pass, Google's need for the web started to wane. They directly embed lifted facts into the search results, tried to push AMP to keep us from going to websites, etc. Google's decisions and technologies have been designed to keep us in their funnel. Web tech has been nudged and mutated to accomplish that. It's especially easy to see when the tides change.
- daveac 1y agoI desperately want to back to crafting sites by hand and not reach for react/vue as a default. I do a lot of static and tempory sites that do very little
- chipsrafferty 1y agoUse HTMX.
- librasteve 1y agothis (and this https://harcstack.org https://harcstack.org)
- insin 1y agoAstro is all the goodness of components but for static sites.
- rorylaitila 1y agoI'm a full stack developer. I do server side rendering. I agree that this is a 'solved problem' for that case. However there are many times I don't want to run a server or a static site generator. I manage a lot of projects. I don't want more build steps than necessary. I just want to put some HTML on the net with some basic includes, without JavaScript. But currently I would go the web component route and accept the extra JS.
- dietsche 1y agoI think the authors of htmx have the same questions :)
- librasteve 1y agothis! (and this https://harcstack.org https://harcstack.org)
- simonjgreen 1y agoI know it’s not straight HTML, but SSI (server side includes) helped with this and back in the day made for some incredibly powerful caching solutions. You could write out chunks of your site statically and periodically refresh them in the server side, while benefitting from serving static content to your users. (This was in the pre varnish era, and before everyone was using memcached) I personally used this to great success on a couple of Premier League football club websites around the mid 2000s.
- thayne 1y agoOne benefit of doing it on the client is the client can cache the result of an include. So for example, instead of having to download the content of a header and footer for every page, it is just downloaded once and re-usef for future pages
- Sesse__ 1y agoHow big are your headers and footers, really? If caching them is worth the extra complexity on the client plus all the pain of cache invalidation (and the two extra requests in the non-cached case).
- youngtaff 1y agoI’m willing to bet the runtime overhead of assembly on the client is going to be larger than the download cost of the fragments being included server or edge side and cached
- john_the_writer 1y agoIf you measure download cost in time then sure.. If you measure download cost in terms of bytes downloaded, or server costs, then nope. The cost would be smaller to cache.
- youngtaff 1y agoNot necessarily, compression is really effective at reducing downloaded bytes In server terms the overhead of tracking one download is going to be less that the overhead of tracking the download of the multiple components And for client side caching to be any use then a visitor would need to view more than one page and the harsh reality is many sessions are only one page long e.g. news sites, blogs etc
- WhyNotHugo 1y agoHTML frames solved this problems just fine, but they were deprecated in favour of using AJAX to replace portions of the body as you navigate (e.g.: SPAs). I still feel like frames were great for their use case.
- Devasta 1y agoHonest answer: because any serious efforts to improve HTML died 20 years ago, and the web as it's envisaged today is not an infinite library of the worlds knowledge but instead a JavaScript based and platform. Asking for things that the W3C had specced out in 2006 for XML tech is just not reasonable if it doesn't facilitate clicks.
- simultsop 1y agoIt'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.
- Andrex 1y agoHTML5 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.)
- deleted 1y ago[deleted]
- dheera 1y agoSeems everyone forgot HTML-SSI which worked something like this. Many servers and hosting websites of the 90s supported it. <!--#include virtual="header.html" --> Some content here <!--#include virtual="footer.html" -->
- socalgal2 1y agoThere 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 include2.html, not include1.html? You could do the opposite, you can have article1.html, article2.html, article3.html etc, each include header.html, footer.html, navi.html. Ok, that works, but now you've make it so making a global change to the structure of your articles requires editing all articles. In other words, if you want to add comments.html to every article you have to edit all articles and you're back to wanting to generate pages from articles based on some template at which point you don't need the browser to support include. I also suspect there would be other issues, like the header wants to know the title, or the footer wants a next/prev link, which now require some way to communicate this info between includes and you're basically back to generate the pages and include not being a solution I think if you work though the issues you'll find an HTML include would be practically useless for most use cases.
- deleted 1y ago[deleted]
- int_19h 1y agoThese 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.
- socalgal2 1y ago> These are all solvable issues with fairly obvious solutions. No, they are a can of worms and decades of arguments and incompatibilities and versioning > But the latter is already handled by iframes iframes don't handle this case because the page can not adjust to the iframe's content. There have been proposals to fix this but they always run into issues. https://github.com/domenic/cooperatively-sized-iframes/issues https://github.com/domenic/cooperatively-sized-iframes/issue...
- deleted 1y ago[deleted]
- Kuyawa 1y agoThis is the closest we can do today: -- index.html <html> <body> <script src="header.js"></script> <main> <h1>Hello includes</h1> </main> <script src="footer.js"></script> </body> </html> -- header.js document.currentScript.outerHTML = ` <header> <h1>Header</h1> </header>` -- footer.js document.currentScript.outerHTML = ` <footer> <h1>Footer</h1> </footer>` Scripts will replace their tags with html producing a clean source, not pretty but it works on the client
- Bjartr 1y agoYou could even have a server wrap static html resources in that js if you request them a certain way, like <script src="/include/footer.html"> For /footer.html But then you probably might as well use server side includes
- johnisgood 1y agoPretty sure it is possible without JavaScript, too.
- Kuyawa 1y agoOr this: <body> <include src="header.html"></include> <main> <h1>Hello includes</h1> </main> <include src="footer.html"></include> </body> <script> (async function include(){ const objs = document.getElementsByTagName('include') const tags = Array.from(objs) for(tag of tags){ const src = tag.getAttribute('src') const data = await fetch(src) const html = await data.text() tag.outerHTML = html } })() </script> * beware autoclosing tags won't work
- mixmastamyk 1y agoLots of rationalization in here—it's always been needed. I complained about the lack of <include src="..."> when building my first site in '94/95, with simpletext and/or notepad! It was not in the early spec, and seems someone powerful wouldn't allow it in later. So everyone else made work arounds, in any way they could. Resulting in the need being lessened quite a bit. My current best workaround is the <object data=".."> tag, which has a few better defaults than iframe. If you put a link to the same stylesheet in the include file it will match pretty well. Size with width=100%, though with height you'll need to eyeball or use javascript. Or, Javascript can also hoist the elements to the document level if you really need. Sample code at this site: https://www.filamentgroup.com/lab/html-includes/ https://www.filamentgroup.com/lab/html-includes/
- msie 1y agoSome people are too smart for their own, and ours, good.
- aquova 1y agoI 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.
- mikewarot 1y agoThe reason is simple, HTML is not a hypertext markup language. Markup is the process of adding commentary and other information on top of an existing document, and HTML is ironically incapable of doing the one thing it most definitely should be able to do. It's so bad, that if you want to discuss the markup hypertext (I.E. putting notes on top of an existing read only text files, etc.) you'll have to Google the word "annotation" to even start to get close. Along with C macros, Case Sensitivity, Null terminated strings, unauthenticated email, ambient authority operating systems, HTML is one of the major mistakes of computing. We should have had the Memex at least a decade ago, and we've got this crap instead. 8(
- nsonha 1y agothe web platform is the tech stack version of the human concept of "failing upward". It sucks but will only get more and more vital in the modern tech scene as time goes by.
- dfabulich 1y agoWe know why HTML alone can't do includes! In https://github.com/whatwg/html/issues/2791 https://github.com/whatwg/html/issues/2791 the standards committee discussed this. The issue has been open for years. The first naysayer was @dominic: https://github.com/whatwg/html/issues/2791#issuecomment-311365657 https://github.com/whatwg/html/issues/2791#issuecomment-3113... > I don't think we should do this. The user experience is much better if such inclusion is done server-side ahead of time, instead of at runtime. Otherwise, you can emulate it with JavaScript, if you value developer convenience more than user experience. The "user experience" problem he's describing is a performance problem, adding an extra round-trip to the server to fetch the included HTML. If you request "/blog/article.html", and the article includes "/blog/header.html", you'll have to do another request to the server to fetch the header. It would also prevent streaming parsing and rendering, where the browser can parse and render HTML bit-by-bit as it streams in from the server. Before you say, "so, what's the big deal with adding another round trip and breaking the streaming parser?" go ahead and read through the hundreds of comments on that thread. "What's the big deal" has not convinced browser devs for at least eight years, so, pick another argument. I think there is a narrow opening, where some noble volunteer would spec out a streaming document-fragment parser. It would involve a lot of complicated technical specification detail. I know a thing or two about browser implementation and specification writing, and designing a streaming document-fragment parser is far, far beyond my ken. But, if you care about this, that's where you'd start. Good luck! P.S. There is another option available to you: it is kinda possible to do client-side includes using a service worker. A service worker is a client-side proxy server that the browser will talk to when requesting documents; the service worker can fetch document fragments and merge them together (even streaming fragments!) with just a bit of JS. But that option kinda sucks as a developer experience, because the service worker doesn't work the first time a user visits your site, so you'd have to implement server-side includes and also serve up document fragments, just for second-time visitors who already have the header cached. Still, if all you want is to return a fast cached header while the body of your page loads, service workers are a fantastic solution to that problem.
- msie 1y agoI bet a lot of other features were implemented without as much forethought and we were ok.
- lerp-io 1y agojust use react or nextjs or whatever and move on jeez
- cr125rider 1y agoChris is an absolute legend in this space and I’m so glad he’s bringing this up. I feel like he might actually have pull here and start good discussions that might have actual solutions.
- tanepiper 1y agoMy first ever website I wrote with mod_include and .shtml - updating a website was just adding a few tags. Also I miss framesets - with that a proper sidebar navigation was easily possible.
- LeonB 1y agoSame here. I’m not saying my first website was impressive — but as a programmer there’s no way I was copying and pasting the same header / footer stuff into each page and quickly found “shtml” and used that as much as possible. Then used the integrated FTP support in whatever editor it was (“HTML-kit” I think it was called?) - to upload it straight to prod. Like a true professional cowboy.
- deleted 1y ago[deleted]
- altogether 1y agojust on point at all why includ this stuff to load more at once... the hole web stuff works since cgi implementations at web services on asyncronity to load just what u actually need... like now most of them are fetch or xhr calls... I mean it makes just sence for onepager to keep the markup a bit more structured... but why u want to make static rendered homepages those days?
- altogether 1y agoat all ...why includ this stuff to load more at once... the hole web stuff works since cgi implementations at web services on asyncronity to load just what u actually need... like now most of them are fetch or xhr calls... I mean it makes just sence for onepager to keep the markup a bit more structured... but why u want to make static rendered homepages those days?
- wodenokoto 1y agoIn the nineties we fixed it with frames or CGI. I still think of it as one of those “if it was fiction it would be unrealistic” things (although, who writes fictional markup standards?)
- stevage 1y agoThey didn't mention frameset (https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/frameset https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...).
- masswerk 1y agoFun fact: this does work with iframes: <ul> <li><a href="about.html" target="display">about</a></li> <li><a href="contact.html" target="display">contact</a></li> </ul> <iframe src="about.html" name="display"></iframe> 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.)
- charrondev 1y agoThe 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.
- masswerk 1y agoI guess, the best you could do is emulating a frameset layout with a fixed navigation and a display frame for the actual content. (By setting the overflow to `hidden` you can get rid of the outer scrollbars.)
- numpad0 1y agoLike MHTML/MHT/MIME HTML files? Browsers could load *.mht files that included everything. IE, Firefox, Chrome all used to support it.
- jiffygist 1y agoOn 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...
- cenamus 1y agoProbably m4 aswell, but the syntax isn't really pretty by todays standards
- superkuh 1y agoI still use server side includes. It is absolutely the best ratio of templating power to attack surface. SSI basically hasn't changed in the last 20 years and is solid in apache, nginx, etc. You can avoid all the static site generator stuff and just write pure .html files. It should not have gone away. It never did for me. Also, this is kind of what 'frames' were and how they were used. Everything old is new again.
- panny 1y agoSVG use element can do exactly what the OP desires. SVGs can be inlined in html and html can be inlined in SVG too. I never understand why web devs learn html and then stop there instead of also learning svg which looks just like html, but with a lot more power.
- psychoslave 1y agoWe have the object tag, don't we? Is there anything wrong with it? https://www.w3.org/TR/WD-html40-970708/struct/includes.html#h-7.7.4 https://www.w3.org/TR/WD-html40-970708/struct/includes.html#...
- jraph 1y agoYou can't include a menu like this. Clicking on a link in a menu included like this won't work.
- Cort3z 1y agoKind of serious question. Do we have any alternatives to html? If not, why? It’s essentially all html. Yes, browser will render svg/pdf/md and so on, but as far as I can tell, it’s not what I consider "real web" (links to other documents, support for styling, shared resources, scripting, and so on ). I would have loved for there to be a json based format, or perhaps yaml, as an alternative to the xml- based stuff we have today.
- panny 1y ago>links to other documents, support for styling, shared resources, scripting, and so on SVG supports all those things. SVG's use element can do exactly what the OP is talking about. You can put HTML in SVG and SVG in HTML. SVG is just markup exactly like HTML. SVG supports JavaScript and stylesheets. SVG can put text on a curve and other stylish things that boring boxy HTML cannot accomplish. https://www.w3.org/2002/Talks/www2002-svgtut-ih/hwtut.pdf https://www.w3.org/2002/Talks/www2002-svgtut-ih/hwtut.pdf Read it. Ch 11 shows you how use can import chunks of other SVG. Ch 12 is JavaScript. You can inline it in your html and style it with CSS just like any of the other tags in html. Once you know SVG, you can hand generate more compact images than anything created by something like Inkscape which just uses path elements for everything. For example, you can do a UPC barcode with a single SVG line element using a wide stroke and a stroke-dasharray. See chapter 8.
- davidfstr 1y agoFor HTML-in-HTML natively I use iframes and still remember how to use Frames & framesets.
- msie 1y agoWhen I read all the arguments against, I think: “Perfect is the enemy of good.”
- nitwit005 1y agoThis seems to be forgetting the need to render other site's content. That's the main reason for iframes to be used, as people need to render ads, email previews, games, and so forth, without potentially breaking the rest of the page. The "extremely awkward" aspect they complain about is a side effect of needing to handle that case. You could add some nicer way to include content for the same domain, but I suspect having two highly similar HTML features would be fairly awkward in practice, as you'd have to create a whole new set of security rules for it.
- JanSchu 1y agoWhy can’t I just write <include src="header.html"> and be done with it? We almost could. Chrome shipped a draft of HTML Imports back in 2014. You’d do exactly that, the browser would fetch the fragment, parse it, and make it available for insertion. The idea died for three reasons that still apply today: Execution‑order and performance hazards. Images, scripts, and styles are fire‑and‑forget: the preload scanner sees a URL, starts the fetch, and the parser keeps streaming. With HTML fragments you need the full subtree before you can finish parsing the parent document (otherwise IDs, custom‑element upgrades, <script defer>, etc. fire in the wrong order). That either stalls the parser—horrible for TTFB—or forces async insertion, which produces layout shifts. Everyone hated both outcomes. Security and isolation. If an imported fragment can run scripts it becomes an XSS foot‑gun; if it can’t run scripts it breaks a surprising amount of markup (think onerror, custom elements with module scripts, CSP inheritance, etc.). The platform already has an “HTML that can’t run scripts” container: it’s called an iframe. Anything more permissive lands in a swamp of half‑trusted execution. The “circular dependency” tar‑pit. Templates inherit CSS scopes, custom element registries, and base URLs from the document that instantiates them. Once you let HTML pull in more HTML, those scopes can nest arbitrarily—and can link back to parents. The HTML spec team tried to spec out the edge‑cases and basically threw up their hands. (There’s a famous TAG thread titled “HTML Imports considered harmful” that reads like war diaries.) Meanwhile developers solved the “shared header” problem higher up the stack—SSI, PHP include, SSG partials, React components, you name it—so browser vendors didn’t see a payoff big enough to justify the complexity. The attitude became: “composition is a build‑time concern, not a runtime primitive.” Could it ever come back? Maybe, but the bar is higher now that everyone has a build step. A proposal would need to: Stream (no parser‑blocking) Sandbox (no ambient script execution) Deduplicate (avoid circular fetch hell) Play nicely with CSP, SRI, origin isolation, and the module graph That starts to look a lot like… <iframe src="header.html" loading="eager">, which we already have—just not the ergonomic sugar we wish for. So the short answer is: HTML includes are easy in user‑land but devilishly hard to make safe, fast, and spec‑compliant in the browser itself.