Re: Making all elements and attributes that contain hyphens valid

Jirka Kosek writes:

> On 16.10.2013 15:10, Smylers wrote:
> 
> > (Or, if all attributes with hyphens in were deemed safe for authors
> > to use like this, that would prevent any future applicable spec from
> > defining any new attributes with hyphens in them: they may clash
> > with attributes authors or libraries are already using. That'd
> > either be a massive restriction on future applicable specs,
> > preventing any of them from using their own foo-* prefix on
> > attributes.)
> 
> I don't see any guarantee here. Author of any library can write down
> sentence stating "This is applicable spec for my FOO library. This
> applicable spec extends HTML5 by attributes prefixed foo-.".

Indeed. But he only needs to do that if he needs for any user agents or
anything other than his library code to interpret the attributes.

If his library is the only thing acting on those attributes then he can
stick to using data-foo-*, and he does know that HTML won't invent a
clashing attribute which activates behaviour in user agents.

> Then nothing will prevent him using foo-, it will be within bounds of
> the current HTML5 and possible clashes will not be prevented.

It will be within the bounds of HTML + Foo, which isn't quite the same
thing.

A specification can't really declare itself to be applicable; that's a
matter of whether users choose to apply it. If a user chooses to use
HTML + Foo rather than plain HTML, then, yes, there is the risk of a
clash between Foo and later extensions to HTML.

> After all possible clashes to my knowledge can be prevented in two
> ways -- either by having central registry for prefixes or by using
> some indirect mechanism like namespaces.

Yes. And data- is a namespace: specifically, it's a namespace that says
‘these attributes are within the jurisdiction of JavaScript run by the
site, and shouldn't be messed with by user agents’. It can only clash
with other things brought in by the site developers, not by changes made
to future user agents.

> So insisting on using data-* for libraries is little bit hypocritical
> -- it just requires typing additional 5 characters and doesn't bring
> any real advantage.

It brings the advantage of being sure that a future version of HTML
won't mint a clashing attribute that could cause the site to cease
working _without the developers changing anything_ (or indeed, if
external developers were used to create the site in the first place and
nobody technical is really involved with it any more).

> In my opinion we should either allow prefixed attributes and require
> prefixes to be registered in some sort of Wiki or introduce something
> like XML namespaces in HTML syntax.

I've no objection to those.

But for an author just wanting to create a library and start using it,
without having to perform any admin steps at all such as registering it,
it's better for their attributes to be safely within data-* than
polluting the global attribute namespace, and the spec should continue
to advise that.

And even for authors who would be willing to register, it should be
pointed out that this isn't necessary if nothing other than your own
library will ever be using the attributes.

Cheers

Smylers
-- 
Stop drug companies hiding negative research results.
Sign the AllTrials petition to get all clinical research results published.
Read more: http://www.alltrials.net/blog/the-alltrials-campaign/

Received on Thursday, 17 October 2013 08:50:29 UTC