What are the concrete risks of using custom HTML attributes?

前端 未结 6 628
别跟我提以往
别跟我提以往 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:34

    Or is it conceivable that some browsers will change to "quirks mode" and render the page as if it was something other than strict HTML 4.0?

    No, bad attributes will not force a rendering mode change.

    If you don't care about validation do what you like, but validation is a useful tool for detecting simple mistakes that can otherwise have you chasing around debugging. Given that there are many other perfectly good alternatives for passing data to JavaScript I prefer to use one of those, rather than forgo validation.

    Plus, when you add an arbitrary attribute you are effectively playing in a global namespace. There's no guarantee that some future browser or standard won't decide to use the name ‘translationkey’ for some new feature that'll trip your script up. So if you must add attributes, give them a name that's obscure and likely to be unique, or just use the HTML5 data- prefix already.

提交回复
热议问题