HTML 5 - 尽可能尽早采用 - 好还是坏?

发布于 2024-07-24 06:34:57 字数 1203 浏览 10 评论 0原文

这个问题的灵感来自这个问题,其中推荐使用最多得票的答案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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

久随 2024-07-31 06:34:57

有几件事需要考虑:

  1. 首先,验证并没有多大意义,因为 HTML 页面很可能是有效的,但编写不当、无法访问等。请参阅 对“有效 HTML”图标说“不”将 XHTML 作为 text/html 考虑有害(参考另一个回复中提到的 hobo-web 测试)
  2. 鉴于此,我强烈建议使用新的 DOCTYPE:在 HTML5 中使用它的唯一原因是它是在浏览器中触发标准模式的最小的东西,所以如果你想要标准模式,就使用它; 您几乎没有理由使用另一个冗长且容易出错的 DOCTYPE
  3. 至于表单增强功能,您可以使用 Weston Ruter 的 webforms2 JS 库将其带到非感知浏览器
  4. ,最后,关于 data-* 属性,它 a) 适用于所有浏览器(只要您使用 < code>getAttribute()),b) 仍然比滥用 titleclass 属性更好,并且 c) 不会像我们所说的那样打扰您进行验证早些时候,验证并不那么重要(当然很重要,但如果有效性错误是故意的,那么您的页面无效也没关系;并且您已经可以在 W3C 验证器中使用 HTML5 验证, 所以...); 所以也没有真正的理由不使用它们。

There are several things to consider:

  1. First, validation doesn't mean that much, because an HTML page can very well be valid but badly authored, inaccessible, etc. See Say no to "Valid HTML" icons and Sending XHTML as text/html Considered Harmful (in reference to the hobo-web tests mentioned in another response)
  2. Given this, I'd highly recommend using the new DOCTYPE: the only reason for having it in HTML5 is that it's the smallest thing that triggers standards mode in browsers, so if you want standards mode, go with it; you have little to no reason to use another, verbose, error-prone DOCTYPE
  3. As for the forms enhancements, you can use Weston Ruter's webforms2 JS library to bring it to non-aware browsers
  4. and finally, about the data-* attributes, it a) works in all browsers (as long as you use getAttribute()), b) is still better than abusing the title or class 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.
清秋悲枫 2024-07-31 06:34:57

好问题!

简而言之:这取决于您的环境和风险承受能力:)

稍微长一点:

  • 认为在早期采用技术方面挑战极限总是好的。 它使您在商业世界中比后来者更具优势,并且还使您在影响技术出现时拥有更大的影响力。

  • 如果您不想重新编写代码或更新源代码,那么早期采用可能不适合您。 想要编写可靠、稳定且永远不需要更改的代码是完全值得尊重的,但这完全取决于您(和您的业务环境)

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)

忘年祭陌 2024-07-31 06:34:57

如果您的页面严重依赖搜索引擎放置,则可能值得考虑某些引擎优先验证 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.

心如狂蝶 2024-07-31 06:34:57

在至少在一种浏览器中测试新功能之前,请不要使用它们。 例如,如果您使用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.

百善笑为先 2024-07-31 06:34:57

请参阅稳健性原则

在 RFC 761(传输控制
协议,1980)美国计算机
科学家乔恩·波斯特尔总结
提前沟通所需的信息
互操作性标准
互联网协议(参见 IEN 1111、RFC
第760章)如下:

TCP 实现应遵循
鲁棒性的一般原则:be
在你所做的事情上保持保守
你所接受的东西是自由的
其他

所以,恕我直言,不。

See Robustness principle:

In RFC 761 (Transmission Control
Protocol, 1980) American computer
scientist Jon Postel summarized
earlier communications of desired
interoperability criteria for the
Internet Protocol (cf. IEN 1111, RFC
760) as follows:

TCP implementations should follow a
general principle of robustness: be
conservative in what you do, be
liberal in what you accept from
others
.

So, imho, no.

黑凤梨 2024-07-31 06:34:57

在至少获得所有主要浏览器的支持之前,我不会实现 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.

我一向站在原地 2024-07-31 06:34:57

我只是为了乐趣和学习而使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文