How important is W3C XHTML/CSS validation when fin

2019-01-20 08:40发布

Even though I always strive for complete validation these days, I often wonder if it's a waste of time. If the code runs and it looks the same in all browsers (I use browsershots.org to verify) then do I need to take it any further or am I just being overly anal?

What level do you hold your code to when you create it for:

a) yourself b) your clients

P.S. Jeff and company, why doesn't stack overflow validate? :)

EDIT: Some good insights, I think that since I've been so valid-obsessed for so long I program knowing what will cause problems and what won't so I'm in a better position than people who create a site first and then "go back and fix the validation problems"

I think I may post another question on stack overflow; "Do you validate as you go or do you finish and then go back and validate?" as that seems to be where this question is going

9条回答
冷血范
2楼-- · 2019-01-20 09:16

I think this is an area in which you should strive to use the Robustness principle as far as is practical (which is good advice for any area of coding). Just because something works today doesn't mean it will work tomorrow: if you're relying on a particular HTML/CSS hack or even if you've just been a little lax in emitting strictly valid code, the next iteration of browsers could well break. Doing it once the right way minimises this problem (though does not entirely mitigate it).

There is a certain element of pragmatism to take here, though. I'd certainly do all I could for a client's site to be valid, but I would be willing to take more risks in my own space.

查看更多
放荡不羁爱自由
3楼-- · 2019-01-20 09:17

I know this isn't answering your whole question, but it is worth considering that by using completely valid html you can be sure that your website should work properly in future web browsers that haven't been released yet.

查看更多
Juvenile、少年°
4楼-- · 2019-01-20 09:19

For understanding why validation matters, it is needed to understand how a browser works at its different layers, and also a little bit about the history of web from the perspective of web browsers.

The HTML you give to a browser is interpreted by the browser following the DOM, an application programming interface that maps out the entire page as a hierarchy of nodes. Each part of that tree is a type of node containing different kinds of data. DOM (Document Object Model) was necessary because of the diversity of HTML pages that early web browsers (Netscape, IE...) implemented to allow alter the appearance and content of a web page without reloading it. For preserving the cross-platform nature of the web, W3C wanted to fix the different implementation of those browsers, proposing DOM.

DOM support became a huge priority for most web browsers vendors, and efforts have been ongoing to improve support on each release. So, it worked.

DOM is the very basic step with which a web browser starts. Its main flow is:

  1. parsing HTML to construct the DOM tree
  2. render tree construction
  3. layout of the render tree
  4. painting the render tree

The step 1 gives the content tree, with the tags turned to DOM nodes. The step 2 gives the render tree, containing styling information.

So, why validation matters: because content tree and render tree are the basis from which the web browser start its job. The most they are well defined, the better for the web browser.

Ultimately, the DOM is also the basis for your JavaScript events. So, its validation helps to the interaction layer too.

查看更多
登录 后发表回答