As data- attributes become more popular, have people found themselves clashing with libraries that hog common names?

If so, do you use a namespace? I'd be interested to know what practices people are using.

For example a common namespacing technique from other disciplines is:

com.example.myname

e.g.

So perhaps for data- attributes it could be data-com-example-height, but that's pretty verbose.

What is the best way you have found?

This is quite subjective, so perhaps not hugely welcome on SO, but perhaps would make a nice wiki page. Feel free to vote to close if it's completely inappropriate.

有帮助吗?

解决方案

It seems reasonable if you are publishing a library to prefix with e.g. the name of your library (data-foolib-bar) to avoid conflicts when redistributing. It's probably overkill for code that's not intended for redistribution.

I think that if you're running into clashes like that, it's probably a sign of overuse/abuse of data attributes.

Consider also combining them into a single attribute, eg data-foolib='{"foo":1,"bar":false}'.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top