Taritsyn/WebMarkupMin

Minification Failing - GTM no script tags breaking minification

NikRimington opened this issue · 5 comments

Hi,

Firstly, this package is awesome, great work.

I'm sure I'm missing something, but I'm attempting to minify a website that has GTM code in it. However it is failing to minify the markup claiming an invalid character in the GTM code:

WebMarkupMin.Core.MarkupMinificationException: Category: HTML_PARSING_ERROR
Message: In the start tag <iframe> found invalid characters.
File: /about
Line number: 64
Column number: 66
Source fragment:

Line 63:     <!-- Google Tag Manager (noscript) -->
Line 64: <noscript><iframe src=https://www.googletagmanager.com/ns.html?id=GTM-12A3BC4
--------------------------------------------------------------------------^
Line 65: height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

Without the GTM code, this page minifies correctly.

So, my question is, how can I identify the invalid characters? or b is there a way to tell the minifier to bypass certain elements like iframes / noscript tags?

Hope you can help.

Thanks

Nik

Typical, after posting this I solved my minification error as someone had removed "'s from the iframe element.

I still wonder if it's possible to bypass the minification for a particular element though?

Hello, Nik!

Could you please provide a full example of code containing an error.

If the full code is as follows:

<noscript><iframe src=https://www.googletagmanager.com/ns.html?id=GTM-12A3BC4 height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

Then this is quite a common HTML parsing error: value of the src attribute containing the slash was not enclosed in quotes. I recommend that you check the code by using a HTML validator.

I still wonder if it's possible to bypass the minification for a particular element though?

Ignoring comment tags can be used for this purpose.

Ahh perfect thank you @Taritsyn, yes the issue was that the src wasn't enclosed in quotes which I found shortly after posting the issue typically.

I didn't realise there was the ignore comment tags, that's really useful. Thank you :-)