asyncLiz / minify-html-literals

Minify HTML template literal strings
MIT License
68 stars 14 forks source link

Don't remove attr quotes by default #12

Closed arthurevans closed 4 years ago

arthurevans commented 4 years ago

Removing the quotes around attribute values can cause cryptic errors in lit-html templates (and, I suspect, other string-literal based templating systems).

In particular, an attribute value with bindings like this:

<a href="/details/${category}/${item}">

This value doesn't get parsed correctly by lit-html if the quotes are removed. After processing, we end up with an HTML comment wrapped around the second bound value, like this:

<a href=/details/candy/<!-- Swedish+Fish -->>

I ended up setting the removeAttributeQuotes option to false to prevent this issue, but it seems like it might be a good default:

  options: {
    minifyOptions: {
      removeAttributeQuotes: false
    }
  }
arthurevans commented 4 years ago

Update: I realized that this option is actually off by default in html-minifier (and there's a note saying to use it with care). So, coming down stronger on the side that this should be off by default.