Minifying HTML with mod_pagespeed

1,331 views
Skip to first unread message

Danny Michel

unread,
Mar 4, 2017, 11:56:54 PM3/4/17
to ngx-pagespeed-discuss
Apologies for my ignorance, but I'm not sure where to find this option in the docs.
Collapse white space is an option, but I'm still using W3 Total Cache to minify my actual HTML source code into one line.
Thanks in advance.

Joshua Marantz

unread,
Mar 5, 2017, 6:51:18 AM3/5/17
to ngx-pagesp...@googlegroups.com
What's your goal?  To stop using W3TC?  Why (out of curiosity)?

NPS doesn't have a single minify_html filter, nor are any of the 5 (!) filters that comprise that functionality in CoreFilters because it's not sufficiently safe to do by default.

collapse_whitespace is careful not to operate in the context of a <pre> or <textarea> or a few similar tags.  However, any element can be turned into a 'pre'-formatted one by applying CSS from JS, which we cannot detect by examining HTML.  Also note that it's generally not safe to remove a block of whitespace completely, it can affect formatting, even in a non-pre-like tag.  So I suspect if W3TC is turning an HTML file into a single line then it is likely affecting rendered format.  Hence collapse_whitespace turns multiple whitespace chars into a single char, using a newline if one of those is present to make the resulting file somewhat readable.  Its goal is reasonably safe minification, not obfuscation.

remove_comments might disrupt some packages that encode information in HTML comments that are read by JS.  That's why NPS supports RetainComment directives.

remove_quotes is pretty safe but will introduce validation issues and is only a small benefit.

elide_attributes has proven troublesome in some cases, because JS can read attributes on HTML elements

case-fold HTML I think is usually safe, but is only a small benefit, and actually can break sites that mislabel XML as HTML.



--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/ngx-pagespeed-discuss.
For more options, visit https://groups.google.com/d/optout.

Danny Michel

unread,
Mar 5, 2017, 8:33:15 AM3/5/17
to ngx-pagesp...@googlegroups.com
Thanks for the response.
Yes, I’d like to stop using w3tc as I was hoping ups would take care of a lot of what it did

I’ve used w3tc for years on multiple sites, removing comments and compressing the html to a single line without any adverse effects, but i may have just been lucky.

I suppose the benefit wasn’t huge, but it was something I was used to.

Why do I want to stop using w3tc? I just try not to use many plugins(none at all really), and w3tc is a huge suite, which doesn’t sit well with me, because while it can only benefit the speed of my site(s), it gives me a bloated feeling about an otherwise really light site. Doesn’t make much sense, but i like to take care of these things on a more root level rather than depending on plugins.

I understand the reasons for not including it in ps, but other ‘non safe’ functionality has been included, and i was just wondering why this one has been skipped totally.


Thanks again

Joshua Marantz

unread,
Mar 5, 2017, 8:41:23 AM3/5/17
to ngx-pagesp...@googlegroups.com
The only thing that we skipped, I think, was whether we eliminate all whitespace characters or collapse many-to-one.  The reason that we skipped that was that what collapse_whitespace currently does is much safer than eliminating all the whitespace, which is almost certain to change appearance.  I think you kind of have to go out of your way to break collapse_whitespace as we currently have it.

Note that you might be fine with the results from eliminating all whitespace -- it won't necessarily look broken, but it will usually change some aspect of rendering.

-Josh

Reply all
Reply to author
Forward
0 new messages