question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why not using HTML5 data-* attributes

See original GitHub issue

Hi, is there a good reason why you don’t go with the data-* attributes and invent your own standard with v-*?

From https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes:

In addition, search crawlers do not index data attributes’ values.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:5
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

18reactions
yyx990803commented, Oct 7, 2016

Note the difference between valid HTML syntax vs fully-valid HTML. The former means it adheres to the syntax constraints laid out in the spec, and only the syntax; the latter entails following the spec to every extreme detail, e.g. if an element doesn’t have a certain attribute then you cannot use it on that element.

At the syntax level attribute names are defined as follows:

Attributes have a name and a value. Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), “>” (U+003E), “/” (U+002F), and “=” (U+003D) characters, the control characters, and any characters that are not defined by Unicode.

So all Vue templates are valid HTML at the syntax level. We have practical reasons to do that because it enables any spec-compliant HTML parser to be able to parse Vue templates - this makes it possible to reuse excellent HTML-based tools already out there in all aspects of tooling. However, it is my opinion that striving for fully-valid HTML in a templating syntax is completely pointless, because the template is not what eventually gets rendered in the browser. The template’s job is to convey the connection between your JavaScript model and the final desired output (which should be, and will be fully-valid HTML). Making your templates fully valid HTML has zero practical benefits except for maybe getting rid of the warnings from your overly-rigorous IDE.

10reactions
FibreFoXcommented, Nov 9, 2016

Maybe it would be a good idea to document this design-decision somewhere inside the vue-documentation. As the attributes are not “XML-attribute”-compatible (because they are containing the colon sign U+003A) this must have been decided sometime in the past.

Any relation to some specs for HTML5 would be nice, there seems a lot of confusion about this whole “data-” thing. Don’t get me wrong, I used to understand HTML differently, but it seems to “just work” inside the browsers … but fails for syntax-checker even like the w3c-markup checker. I tried some dummy website of mine, how the syntax checker sees some v-on:click and attributes, and it fails with errors like Attribute v-if not allowed on element div at this point.. When there is some evaluation about used web-frameworks, and the customer requires the website to be syntax-checker-compliant, then Vue can’t be used.

Could we (developers) please have some references where the design-decision are coming from? (and yes, it feels a bit odd to “discuss” this on some closed issue …)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using data attributes - Learn web development | MDN
HTML is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined...
Read more >
How You Can Use HTML5 Custom Data Attributes and Why
Gajendar Singh walks you through HTML5 custom data attributes, why they're useful, how to style them with CSS and manipulate them with ......
Read more >
Don't use data attributes to find HTML elements with JS - intuio
Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes...
Read more >
Is there any problem with using HTML5's "data-*" attributes for ...
I want to associate some custom data with some HTML nodes. I was going to use the new HTML5 style 'data-*' attributes. e.g.:...
Read more >
HTML5 Data Attributes - Medium
data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found