HTML 5 - 尽可能尽早采用 - 好还是坏?
这个问题的灵感来自这个问题,其中推荐使用最多得票的答案HTML 5 的一项功能。对我来说,这当然是一个很好的方法,但它让我对使用未来规范中的功能感到好奇。
HTML 5 提供了许多不错的改进,其中许多改进可以在当前浏览器中使用而不会引起问题。
一些示例:
// new, simple HTML5 doctype (puts browsers in standards mode)
<!doctype HTML>
// new input types, for easy, generic client side validation
<input type="email" name="emailAddress"/>
<input type="number" name="userid"/>
<input type="date" name="dateOfBirth"/>
// new "required" attribute indicates that a field is required
<input type="text" name="userName" required="true"/>
// new 'data-' prefixed attributes
// for easy insertion of js-accessible metadata in dynamic pages
<div data-price="33.23">
<!-- -->
</div>
<button data-item-id="93024">Add Item</button>
许多新功能旨在使浏览器能够自动验证表单,并为它们提供更好的输入(例如日期选择器)。 有些只是方便,似乎是为未来做好准备的好方法。
目前,它们不会破坏当前浏览器中的任何内容(据我所知),并且它们允许干净、通用的客户端代码。
然而,尽管它们在 HTML 5 中都有效,但它们对于 HTML 4 无效,并且 HTML 5 目前仍是草案。
尽早使用这些功能是个好主意吗?
是否存在我尚未意识到的浏览器实现问题?
我们现在应该开发利用 HTML 5 草稿功能的网页吗?
This question was inspired a bit by this question, in which the most upvoted answer recommended using a feature from HTML 5. It certainly seemed to be a good method to me, but it made me curious about using features from a future spec in general.
HTML 5 offers a lot of nice improvements, many of which can be used without causing problems in current browsers.
Some examples:
// new, simple HTML5 doctype (puts browsers in standards mode)
<!doctype HTML>
// new input types, for easy, generic client side validation
<input type="email" name="emailAddress"/>
<input type="number" name="userid"/>
<input type="date" name="dateOfBirth"/>
// new "required" attribute indicates that a field is required
<input type="text" name="userName" required="true"/>
// new 'data-' prefixed attributes
// for easy insertion of js-accessible metadata in dynamic pages
<div data-price="33.23">
<!-- -->
</div>
<button data-item-id="93024">Add Item</button>
Many of these new features are designed to make it possible for browsers to automatically validate forms, as well as give them better inputs (for example a date picker). Some are just convenient and seem like a good way to get ready for the future.
They currently don't break anything (as far as I can tell) in current browsers and they allow for clean, generic clientside code.
However, even though they are all valid in HTML 5, they are NOT valid for HTML 4, and HTML 5 is still a draft at this point.
Is it a good idea to go ahead and use these features early?
Are there browser implementation issues with them that I haven't realized?
Should we be developing web pages now that make use of HTML 5 draft features?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有几件事需要考虑:
data-*
属性,它 a) 适用于所有浏览器(只要您使用 < code>getAttribute()),b) 仍然比滥用title
或class
属性更好,并且 c) 不会像我们所说的那样打扰您进行验证早些时候,验证并不那么重要(当然很重要,但如果有效性错误是故意的,那么您的页面无效也没关系;并且您已经可以在 W3C 验证器中使用 HTML5 验证, 所以...); 所以也没有真正的理由不使用它们。There are several things to consider:
data-*
attributes, it a) works in all browsers (as long as you usegetAttribute()
), b) is still better than abusing thetitle
orclass
attributes and c) won't bother you with validation as we said earlier that validation isn't that important (of course it is, but it doesn't matter that your page is invalid if the validity errors are willful; and you can already use HTML5 validation in the W3C validator, so...); so there's no real reason not to use them either.好问题!
简而言之:这取决于您的环境和风险承受能力:)
稍微长一点:
我认为在早期采用技术方面挑战极限总是好的。 它使您在商业世界中比后来者更具优势,并且还使您在影响技术出现时拥有更大的影响力。
如果您不想重新编写代码或更新源代码,那么早期采用可能不适合您。 想要编写可靠、稳定且永远不需要更改的代码是完全值得尊重的,但这完全取决于您(和您的业务环境)
Good question!
In short: it depends on your context, and risk tolerance :)
Slightly longer:
I think it's always good to push the envelope on early adoption of technology. It gives you an advantage over late-comers in the commercial world, and also gives you much more leverage in influencing the technology as it emerges.
If you don't want to have to re-write code, or update your source, then early adoption may not be for you. It's perfectly respectable to want to write solid, stable code that never has to change, but it's entirely up to you (and your business context)
如果您的页面严重依赖搜索引擎放置,则可能值得考虑某些引擎优先验证 HTML(来源:http://www.hobo-web.co.uk/seo-blog/index.php/official-google-prefers -valid-html-css/)。
此外,值得考虑的是,依赖新的日期输入元素(例如 Opera 中的元素,可能还有其他元素)可以为开发人员提供更多便利,它通常会排除包含更复杂的 Javascript 控件,而这些控件将更好地服务于旧版浏览器(通常会退回到简单的文本输入字段)。
当然,一如既往,不要依赖浏览器端检查并验证所有输入服务器端。
If your page relies heavily on search engine placement, it may be worth considering that some engines give priority to validating HTML (Source: http://www.hobo-web.co.uk/seo-blog/index.php/official-google-prefers-valid-html-css/).
Also, it is worth considering that relying on the new date input elements (such as those in Opera, possibly others) allows for more convenience on the part of the developer, it typically precludes including more complex Javascript controls which would better server older browsers (typically falling back to a simple text input field).
Of course and as always, don't rely on browser side checks and validate all input server side.
在至少在一种浏览器中测试新功能之前,请不要使用它们。 例如,如果您使用now表单功能,请务必在Opera中进行测试。 否则,你可能会因助长有毒的遗产而弊大于利。
当某个功能已经在浏览器中实现并且您正在使用这些浏览器进行测试时,当然,请使用新功能。
另请参阅旧答案。
Please don’t use the new features before you can test them in at least one browser. For example, if you use the now form features, be sure to test in Opera. Otherwise, you’ll likely do more harm than good by contributing to a poisoned legacy out there.
When a feature is already implemented in browsers and you are testing with those browsers, sure, please use the new features.
See also an older answer.
请参阅稳健性原则:
所以,恕我直言,不。
See Robustness principle:
So, imho, no.
在至少获得所有主要浏览器的支持之前,我不会实现 HTML 的新功能。
客户并不关心您的页面是否有效,他们更关心它是否可以跨浏览器工作。 即使我们努力实施最新标准,仍然会有客户和公司永远不会放弃他们的 IE6,并且 IE6 将在他们的浏览器需求列表中停留一段时间。
新的表单类型受到欢迎,但必须在服务器端检查表单。
将现有文档传递给 HTML5 将需要大量的努力和适应,并且我估计这不会一蹴而就。 预计至少需要 3 年时间才能成为主流。
I will not implement new features from HTML until at least they have support from all major browsers.
Clients don't care if your page is valid, they care much more if it works cross browser. Even if we fight to implement the latest standards there will be still clients and companies that will never shed their IE6, and IE6 will be on their browser requirements list for still a while.
The new form types are welcomed, nevertheless the forms have to be checked in the server side.
Passing to HTML5 existing documents will require a lot of effort and adaptation and in my estimate will not happen overnight. Expect at least a 3 years until it will hit the mainstream.
我只是为了乐趣和学习而使用 HTML 5,但我绝对不会使用这个新标准来触及我的任何生产代码(现有代码),至少到目前为止,直到我有充分的理由支持这一举措。
I would use HTML 5 just for fun and learning, but definitively I wouldn't touch any of my production code (existing code) with this new standard, at least by now and until I have a valid reason to support this move.