What are the concrete risks of using custom HTML attributes?

前端 未结 6 624
别跟我提以往
别跟我提以往 2020-12-09 00:08

This subject turned into a heated discussion at the office, so I\'m interested to learn what you think.

We are working on a web app that only targets some specific b

6条回答
  •  隐瞒了意图╮
    2020-12-09 00:43

    There are no browser limitations/risks. Only the w3 validator will bark, but barking dogs doesn't bite.

    The w3 spec says the following:

    • If a user agent encounters an attribute it does not recognize, it should ignore the entire attribute specification (i.e., the attribute and its value).

    IE will also not render in quirks mode or so as some may think. It will only do that on invalid/forced doctypes, not on invalid attributes.

    However, keep in mind that some Javascript libraries/frameworks will "invisibly" add/use custom HTML attributes in the DOM tree, such as several jQuery plugins do. This way you may risk collisions in attributes because it "by a coincidence" uses an attribute with the same name as you do for your own purposes. Sadly this is often poorly or even not documented at all.

提交回复
热议问题