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}'
.