HTML compression
-
I can see many weird line breaks in compressed HTML like:
<div id="mainsearch"><div class="search-form-box"><form role="search" method="get"I can’t figure out any algorythmic or logic behind this. could this be improved?
thank you for your feedback,
rolf
-
Hi,
What’s your exact concern about this?
Are you possibly getting a warning to minify html on gtmetrix or some other score website?That code looks like your source viewer is just wrapping the text on your window, so it doesn’t look like a linebreak. It goes down possibly due to the screen width, browser settings or server settings (there are ways to enforce line breaks after xx chars for compatibility with some very old browsers).
What happens when you copy paste the source onto a notepad file and disable line wrapping?
Are those still there?Also, how does your theme files look?
Are these specific linebreaks already on the theme?Is this html you’re showing me, inside a <script></script> tag or is it being loaded with ajax?
Linebreaks are preserved inside script tags for javascript compatibility (those matter in javascript code). As for ajax requests, I believe those are not processed since the plugin only targets the main html page (ajax would be a module or extra element loaded by javascript).when I copy the code to an editor I got several lines.
every line in the example above is a line of its own in the editor (Atom, to drop a name).
and that are short lines, no need to break in nearly any window width.when I use a plugin like Minify HTML allthecommentsaregoneandtagsareconcatenatedinonesingleline.
whithout linebreaks.
but it’s one more plugin on the list that I could get rid off to keep the total number of plugins small.I’ll take a better look at the html minification library (third party) but what I can see is that whitespace is being replaced by linebreaks inside html tags… it could be that linebreaks have a smaller footprint than whitespace, but it makes the source a bit strange (but I care more for performance and size, not beauty of code).
If this behavior is something I can change without compromising speed, I’ll release it before Christmas on a new version.
As for js files and large css files, some browsers need frequent linebreaks for things to work smoothly. For example, if you use the Google Compiler for JS minification, this happens:
https://developers.google.com/closure/compiler/faq#linefeedsThe Closure Compiler intentionally adds line breaks every 500 characters or so. Firewalls and proxies sometimes corrupt or ignore large JavaScript files with very long lines. Adding line breaks every 500 characters prevents this problem. Removing the line breaks has no effect on a script’s semantics. The impact on code size is small, and the Compiler optimizes line break placement so that the code size penalty is even smaller when files are gzipped.
YUI Compressor usually makes it into a single line… but then it causes trouble with long files.
Browsers also have limits for css, most notabily IE. If you have too many css rules in one file it will break. http://stackoverflow.com/questions/9906794/internet-explorers-css-rules-limits
This means that we cannot simply minify all css or js into one single line.
wow, cheers and thank you for the insights.
weird stuff.kind regrads – and enjoy christmas!
rolfI am pushing an update today and I’ll include a fix for this.
Thanks.
works like a charme. thanks!
The topic ‘HTML compression’ is closed to new replies.