Swaagie / minimize

Minimize HTML
MIT License
162 stars 18 forks source link

Should not remove empty href as this effects tab order #46

Closed gambrose closed 9 years ago

gambrose commented 9 years ago
<a href="">click me</a>

minimises to

<a>click me</a>

The removal of the href means that this element is no longer included in the tab order.

I am working around this with { empty: true }.

I thing the expected output would be as this does not affect the behaviour.

<a href>click me</a>
Swaagie commented 9 years ago

From what I understand, this is also how it should be 'worked around'. With taborder you should be able to force it in. Is there any specific reason the href has to be empty?

gambrose commented 9 years ago

The link was being used to open a nav menu. It needed to be empty to not cause page navigation, we are using client side routing so could not use #. In the end we changed the ux pattern to not use the empty href.

The reason I reported it as an issue is that browsers behave differently if href is missing or empty. Minimizers should make the html as small as possible while still retaining the same behaviour should then not?

You can set taborder but that is the way to madness and bad ux as things invariably get out of order. Better to use the natural flow of the html to define the tab order. It makes including dynamic content more manageable.

Swaagie commented 9 years ago

I see, I would consider this an extreme edge case. One could argue browsers implement ambiguous behavior. Judging from your example though, wouldn't event.preventDefault have prevented navigation?

The first intent is to maximize the minification. Where options relax this state, so in this case I think the option is more suitable. The option could even be accompanied by a plugin that does remove all empty attributes from other elements than a. Which would then exactly do what you want.

gambrose commented 9 years ago

event.preventDefault would work but I had listeners further up the dom than needed the event to bubble up.

I knew it was an edge case, as I said I have worked around the issue. I'm happy to respect your decision not to fix this issue that you feel too obscure.