8 ms·
HTML suffers badly from this. Even basic lexical syntax, as in tag and comment syntax, is not strictly enforced. Browsers became very forgiving, and in HTML 5
by Animats 9y ago
HTML suffers badly from this. Even basic lexical syntax, as in tag and comment syntax, is not strictly enforced. Browsers became very forgiving, and in HTML 5, recovery from a long list of common errors, including comments with bad syntax, was formalized in the spec. There are pages of error recovery gimmicks defined in the spec, and HTML 5 parsers have to do all that stuff. (This is one reason why html5parser for Python is so slow.) There used to be tricks for doing different things in IE and Firefox based on how they handled errors.
On the first error, a browser should display an error bar in the middle of the page, then proceed on a best-effort basis, ignoring most styling. Bad pages would still be readable in emergencies, but they'd be annoying enough to get fixed.
(Until you write a web crawler, you don't realize how bad HTML is in the wild. There are low-level syntax errors. There are pages with more than one <html>, <head>, or <body> section, or where those sections are out of order. There are nesting errors which result in page trees a thousand deep. There are tags that don't belong in HTML. There's syntactically incorrect ad code from major vendors.)
- whipoodle 9y agoDefinitely. There was an effort to remedy this with draconian error handling (XHTML), and it badly flopped. Edit: I don't mean "draconian" in a pejorative sense, it is just typically the word used to describe this.
- robertlagrant 9y agoFunny how people think that throwing a syntax error is "Draconian" just because it's HTML.
- jacquesm 9y agoBecause an end user has zero recourse after getting such a syntax error. Those are only useful for developers. Graceful error handling is one of the things that set good applications apart from (really) bad ones.
- zAy0LfpBZLC8mAC 9y agoThat is about user errors, not about servers sending garbage. If browsers did strictly enforce HTML syntax, there would be no problem for users at all, because servers simply would not be sending garbage. When an SSL server sends just one bit wrong, that will lead to the connection simply aborting. Have you ever seen that being a problem for users? No, because servers simply implement the frickin spec when deviating from the spec means that your connection gets dropped.
- inimino 9y agoAnd users don't author SSL streams in text editors. You seem to have forgotten what HTML was created for. It's a document format. If a browser did strictly enforce (what, HTML 4.01?) syntax, there would be no problem for users at all, because that browser would not have any users.
- zAy0LfpBZLC8mAC 9y agoJust like Java compilers have no users at all because they refuse to compile broken source code?
- inimino 9y agoIf authors published their Java source code on the Internet, and random casual visitors expected their own existing compiler to run it, you'd see the same competitive forces at work. Now imagine most of those users don't know what a "compiler" is and are using the one that came with their OS. Now imagine you are a competing compiler vendor who worked very hard to get some of those same users to install your compiler specifically. And by the way, users expect the same compiler to compile all the projects and would be shocked and annoyed if they had to use different compilers for different code.
- zAy0LfpBZLC8mAC 9y agoYes, of course there is an explanation for the asshole behaviour of software vendors. That does not make it any better. Introducing and keeping unnecessary deviations from the standard in your software product creates massive costs for other parties in the long run (aka, externalities). Creating those costs in order to gain an advantage in the market is just the behaviour of an asshole.
- eridius 9y agoIt's draconian because an error anywhere in the page causes the entire page to stop rendering, instead of just causing that one small section with the error to stop rendering.
- vageli 9y agoThis behavior is pretty common, though. Typo in variable name in Python? Program will stop mid-execution with a traceback.
- eridius 9y agoYes, but that's source code. You can't run a partially-compiled program, so of course an error anywhere stops everything. But HTML isn't a programming language, it's a markup language, and you absolutely can render a partially-correct page. This might be more obvious if you consider a different markup language instead. Let's say you're using Markdown, and you start an italic block with an asterisk and forget to terminate it. Should the whole comment fail to render, or should it just fall back to showing a partially-correct comment?
- zAy0LfpBZLC8mAC 9y ago> Yes, but that's source code. You can't run a partially-compiled program, so of course an error anywhere stops everything. But you absolutely can compile a program with syntax errors. There is nothing that prevents compiler writers to be equally "forgiving" and just inventing random semantics for stuff that does not have any meaning in the language, just as browsers do with HTML. And it would be just as idiotic.
- eridius 9y agoThat would certainly be idiotic. But that would not be "just as idiotic", because it's not even remotely idiotic to do a partial rendering of a document that has some incorrect markup in it. In fact, your claim there is begging the question.
- cpburns2009 9y agoI recently finished automating a download. I would like to know who thought you should start with a <meta> tag, followed by <script> tags, then the <!DOCTYPE>, then some more <script> tags, and then finally the beginning <html> tag. How do you write this crap? If I had reviewed whatever code generated that mess, I would have unapologetically rejected it.
- im3w1l 9y agoBy concatenating the output of the ads module with the output of the content module.
- Animats 9y agoRight. Ads ought to be in iframes, to contain the effects of ad code, but Google prohibits that.[1] [1] http://searchengineland.com/google-bans-iframes-for-adsense-though-says-it-will-grant-exceptions-81174 http://searchengineland.com/google-bans-iframes-for-adsense-...
- dTal 9y agoSo by strictly following the standard and ignoring anything outside of <html></html>, you'd incidentally block ads as well? Awesome.
- niftich 9y agoIn HTML's case, the mass-market adoption and competing browser landscape meant that being anything other than lax and forgiving was a bad strategy for self-preservation: users would simply get frustrated and switch browsers to one that make better sense of the particular broken page. This conundrum explains the complicated and sometimes haphazard hoops that emerged through the efforts of browser-makers, standards-setters, and web developers to move the landscape forward: weird opt-in magic values for stricter handling, IE's eventual "is the page broken?" button, and the like. HTML5 began as a splinter effort to write down what browsers actually do and mix in enough wishlists of what browsers should do, so it's only natural that they decided to codify many rules of handling broken HTML. While I too question whether it was the smart approach, it was definitely an approach that made sense to the stakeholders and authors of HTML5, who were largely actual vendors of browsers and parsers. Even today, that browser vendors have pushed out all sorts of measures like near-mandatory TLS, stricter parsing of HTML is a goal no one really chases. As an appropriate throwback, see Jeff Atwood on this topic in 2007 [1], complete with screenshots of different styles of browser error handling. [1] https://blog.codinghorror.com/javascript-and-html-forgiveness-by-default/ https://blog.codinghorror.com/javascript-and-html-forgivenes...
- captainmuon 9y agoI wrote a simple HTML parser for a web crawler many years ago. What it did was just record each opening and closing tag, and created a list of (open_pos, end_pos) spans. This was much more general than building a tree, and had no problems with really malformed HTML (such as overlapping tags <b>Bold <i>Both</b> Italic</i>). Funnily, this wouldn't work anymore. The efforts to fix HTML have made it even more complicated. Now browsers insert a lot of fictious tags if you nest things improperly, and you have to simulate that.
- gsnedders 9y ago> This is one reason why html5parser for Python is so slow. I presume you mean html5lib and not the new html5-parser; html5lib isn't slow because of error recovery: html5lib is slow because it's a parser written in Python. The parsing performance is largely taken up, last I benchmarked the VM, by allocation overhead (heck, reading s[0] of a string s causes an allocation) and super-simple VM instructions (primarily dispatch overhead). What I'd like to see is how much faster an HTML parser would be if it rejected any document with a parse error at the first parse error; I doubt it'd be much (you'd still need the branches to detect the parse error, though the code might be smaller and you'd get better cache locality).
- kbenson 9y agoHave a super strict engine that parses as fast as possible, and do a full fail on a parse error and fall back to a more lax engine and start parsing from scratch. People that care about speed will notice that they can get a speedy page by being strict, and those that don't care will see a slight slowdown in their page times. Automatic incentivization of good future behavior.
- zAy0LfpBZLC8mAC 9y agoThat sounds like a path towards fixing this mess that could actually work! I mean, you even could add deliberate delays, simply to incentivise site operators, because they tend to care about even relatively small effects on conversion rates and the like, while for most end users some sluggishness on some bad websites probably would not be enough to cause switching to a different browser?!
- inimino 9y agoThis idea comes up a lot, but it is based on faulty assumptions. First, time parsing HTML is irrelevant compared to network latency and even DOM and CSS work that browsers do. Second, a parser that handled only, say, strict XML would certainly be easier for the parser author to write, but it would be slower than the optimized parsers browsers already have for HTML. If optimized, it still would not be significantly faster than a full HTML5 parser. Your idea wouldn't work because it would never create any noticeable impact on page loading speed even in the best case scenario. That's assuming that browsers want to maintain and ship two totally different parsers, which (cf. XHTML) they don't.
- dredmorbius 9y agoMy familiarity with abysmal quality comes from trying to produce (often manually) useful HTML output, or alternate markup. So not ads. And, yes, it is indeed a sorry state.