Anyone know if there is way to minify the HTML that EE produces please? Can’t see a built in way and nothing on Devotee.
Thanks a lot
Lee
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
October 09, 2010 9:28am
Subscribe [5]#1 / Oct 09, 2010 9:28am
Anyone know if there is way to minify the HTML that EE produces please? Can’t see a built in way and nothing on Devotee.
Thanks a lot
Lee
#2 / Oct 21, 2010 6:33am
Any suggestions?
#3 / Oct 26, 2010 4:59pm
Minifying HTML is tricky business as HTML is often whitespace sensitive and that is the only thing that can be minified.
Don’t get me wrong… I love optimizing stuff, but maybe this is one step too far.
Greetz,
Wouter
#4 / Apr 05, 2011 9:17pm
I’ve been wondering the same for awhile. The HTML white space can grow quite large with conditionals and comments. I’m only 50% complete with a particular section of the site and already over 2200 lines of code where this can be greatly reduced to less than 1000.
I’ve debated in my own mind on whether it’s worth creating 2 template files with 1 being minified by hand. This could get pretty messy and definitely not worth shaving some milliseconds off page load.
I honestly hate large amounts of whitespace in HTML. I picture a plugin where you place all code in between your pair tags and it would at least eliminate any white space that is outside of any curly brackets. It also would be great if EE comments didn’t take up any additional lines. Not sure if this is possible since a comment may be on the same line as code.
#5 / Apr 06, 2011 3:25am
I agree with Wouter here in that this is perhaps a step too far. A lot of whitespace can be gained back by just coding slightly differently in templates. Admitted it’s not always as nice to look at but really the amount of work to do this for the amount of gain is just too much in my opinion.
Sometimes just doing something like :
{exp:channel:entries channel="default_site" disable="member_data|pagination|categories"}{title}
{body}{/exp:channel:entries}can be all that’s needed to gain back some space.
Hope that helps a bit.
Best wishes,
Mark
#6 / Apr 06, 2011 5:38pm
This really depends on your tolerance for white space and your overall objectives. There’s a quickly reached point of diminishing returns here.
For example, all your templates could be minified, one-by-one in EE, and the original code kept separate. Is that worth the effort? The end result is a) perfectly minified code and almost no white space, b) double the effort to manage the code, make edits and tweaks, etc.
Minified web pages might be served and loaded a little faster, but under the right server setup, most of us would be hard pressed to notice a difference.
I try to keep code in each template clean and neat and tight but not overly so. It’s important to be able to go back into the code and figure out how to do something (or, why something was done a certain way) quickly and easily, and that requires a little white space and some commenting.
As to EE doing it, I don’t recall that as an option, but GZIP certainly helps. There are a number of EE plugis which minify CSS and Javascript, including NSM Minify (haven’t tried it). I don’t see one that minifies basic HTML.