I'm learning AngularJS and I found a simple code like this one:
<!DOCTYPE html> <html> <head> <meta charset='utf-8'> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script> </head> <body ng-app ng-init="name = 'World'"> <h1>Hello, {{name}}!</h1> </body> </html>
does not pass W3C validation test, mainly because there are non standard attributes (ng-app
, ng-init
).
The question is: should I care about W3C validation of my application? Should I abandon AngularJS?
W3C validation helps you to get better rankings in search engines (SEO). Errors in your code can affect your site's performance and make a big impact on your site's SEO. Search engines check the HTML or XHTML code of your website when searching.
In general, W3C validation would naturally be seen as something beneficial for SEO. Validating your website is important because there are code errors that can cause serious styling issues from a web design perspective. These are generally the types of errors that also cause a Googlebot not to render.
The Markup Validator is a free service by W3C that helps check the validity of Web documents. Most Web documents are written using markup languages, such as HTML or XHTML . These languages are defined by technical specifications, which usually include a machine-readable formal grammar (and vocabulary).
In simple terms, validation ensures that your website complies with the standards accepted by most web designers. That also means that it will be accessible to more people, across more web browsers and operation systems. Having an accessible website is also regarded as good web design practice.
You could use the data- html5 attribute which is standard and as far as I know works the same for Angular. Something like:
data-ng-app="" data-ng-init="xxx"
Will work the same in Angular and are validated by W3C.
Look also at this: ng-app vs. data-ng-app, what is the difference?
Aside from that, from my experience working with standards is always better when your product will be delivered to a possible large crowd (so you'r building a website or a public webapp and so on) with different clients, versions etc. If you're building a SPA using angular and maybe phonegap to create a mobile app which will be installed on mobile devices as a native app, standard could not be that important, the important thing is that it will work on your target devices.
W3C HTML5 validator maintainer here. We’ve had discussions about how to deal with better facilitating validation of documents that contain custom attributes like Angular’s ng-*
attributes—attributes which though while non-standard are still very widely and correctly used, and so having the validator emit “error” messages about them isn’t really helping authors.
One feature I’ve added to the HTML5 validator to mitigate this is a “Message filtering” feature that lets you persistently ignore error/warning messages that aren’t important or useful to you. The frontend is here:
http://validator.w3.org/nu/
After you submit a document for checking, on the results page you’ll see a Message filtering button, and if you press that, you’ll get a list of all the error messages grouped into sets, with Show/Hide checkboxes.
I added support for custom elements to the HTML Checker (W3C validator)—so, to add support for custom attributes, I could use a mechanism similar to what I used for implementing that.
But the HTML checker can’t be changed to allow custom-attribute names until the HTML spec is updated to allow them. For that, see the proposal in the HTML-spec issue tracker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With