Adds config option to minify HTML output#965
Conversation
|
This is a fantastic idea. Have you given thought on newline characters & how we might handle that with pre/code tags? |
|
I'll modify it to leave <pre> and <code> content untouched. There are a number of open source minifiers around, but there are probably licence incompatibilities. :( |
… and process CSS with its own rules.
|
Well, I'm happy. My landing page is now 30% smaller, and most other pages 10-15%. |
There was a problem hiding this comment.
Can you add a space in there? The most trivial thing in the world but.. , $expire).
|
👍 This would help me a ton :-) |
|
+1 |
3 similar comments
|
+1 |
|
+1 |
|
+1 |
|
Cool. I've had my own makeshift version of this myself that clobbers |
There was a problem hiding this comment.
Any advantage to the newline as opposed to a space?
And I think $output = preg_replace("!\s+!", " ", $output) is a little more readable.
There was a problem hiding this comment.
Replacing only 2+ space occurences should be faster than each single one.
I'd also vote for spaces as opposed to newlines though.
|
The newline instead of space was based on an old and perhaps unfounded superstition I have that having excessively long line-lengths can be an issue. Since newline and space are otherwise functionally the same I saw no harm in it. But if line-lengths are not actually an issue, As far as |
|
I don't think long lines matter much. In fact, I've found that any whitespace between tags is generally superfluous. Look at the source for https://timshomepage.net/, and see how long it takes to find a browser that chokes on it. I basically use a variation of this: https://gist.github.com/1338288 |
There was a problem hiding this comment.
I'm not sure if it makes much of a difference, but this is how I minify CSS: https://gist.github.com/1685711
More verbose in terms of code,but perhaps equivalent in functionality.
|
Yet to have any problems, even on some tricky pages http://d.pr/95kB |
|
I understand the benefits of using So it looks like we're golden here guys. @derekjones @ericbarnes @gaker got anything to say about this one? I've had it enabled for pyrocms and the whole thing seems fine, shaved 1-2kb off each page! |
|
I was currently using |
|
@minerbog it already does this with a single, more efficient regular expression. |
|
Apologies, regex has never been my strongest point!! |
|
@minerbog No worries. |
|
👍👍 |
|
Can we get this one going again? |
|
Somebody else do it. I'm pretty disillusioned with the whole process. On Thu, Jun 14, 2012 at 12:27 PM, Andrey Andreev <
|
|
@atiredmachine don't give up now, it's nearly there. Sometimes you have to bump these things. If you hadn't noticed there are quite a few pull requests knocking around! :) |
|
Ignore that, I've merged it without conflict. Good work and sorry for the delay. I remember thinking this had been merged, searching for it and finding nothing. |
|
Bug reported related to this change #1499 |
|
Hey folks, I'm testing this out and getting an encoding problem for the "à" character. Other french characters seem fine, but this one gives the infamous UTF-8 question mark. Preview : http://www.tribalsolutions.ca/external/minify_encoding.jpg |
|
@svezina Is that character written in UTF-8 or some other encoding? |
|
@narfbg Yep everything is UTF8 coming from a language file. I just did a bit more troubleshooting to make sure it wasn't my app that had a problem.
Here is the result: http://www.tribalsolutions.ca/external/minify2.jpg ADDED: everything is OK if you don't have spaces before and after characters. It only happens if you have spaces around. |
|
Well, that makes sense ... Any UTF-8 character that doesn't need to use both of the bytes that represent it is prefixed (or suffixed, don't remeber) by |
|
Thanks for the explanation! I just made another interesting discovery. It seems to be server-related as well: I'll just use my 5.3 server for dev work then. |
|
It's more likely to be related to the PCRE version that you have available on the server than PHP itself. But anyway ... you can't always have all the exotic features turned on. This feature is way too far from being perfect and I personally would consider it experimental - it was expected that it can cause problems in cases like yours, so for now all I can tell is - if it causes problems, turn it off. :) |
This feature has proven to be problematic and it's not nearly as flexible as a dedicated minifier library like Minify (http://www.minifier.org/, https://github.com/matthiasmullie/minify). The same results in terms of saving traffic can also be achievied via gzip compression (which should also be done on the httpd level, but we also support anyway) and stuff like mod_pagespeed. Reverts PR #965 Related issues as a track record proving how problematic this has been: #2078 #1499 #2163 #2092 #2387 #2637 #2710 #2120 #2171 #2631 #2326 #2795 #2791 #2772 Additionally, the count of contributors suggesting that the only way to fix the minifier problems is to remove it, is around the same as the count of people suggesting the feature to be implemented in the first place. It was experimental anyway ... the experiment failed.
This feature has proven to be problematic and it's not nearly as flexible as a dedicated minifier library like Minify (http://www.minifier.org/, https://github.com/matthiasmullie/minify). The same results in terms of saving traffic can also be achievied via gzip compression (which should also be done on the httpd level, but we also support anyway) and stuff like mod_pagespeed. Reverts PR bcit-ci#965 Related issues as a track record proving how problematic this has been: bcit-ci#2078 bcit-ci#1499 bcit-ci#2163 bcit-ci#2092 bcit-ci#2387 bcit-ci#2637 bcit-ci#2710 bcit-ci#2120 bcit-ci#2171 bcit-ci#2631 bcit-ci#2326 bcit-ci#2795 bcit-ci#2791 bcit-ci#2772 Additionally, the count of contributors suggesting that the only way to fix the minifier problems is to remove it, is around the same as the count of people suggesting the feature to be implemented in the first place. It was experimental anyway ... the experiment failed.
If the $config['minify_output'] setting is set to TRUE, CodeIgniter's output class will process the output with a basic minify function. Will apply minify rules according to the currently set content type (defaults to "text/html" and currently only supports "text/html" "text/css" and an extremely rudimentary minifier for "text/javascript").
Output is minified before the cache is written, so savings are also on diskspace.
According to my tests it typically reduces the content by 8-15%.
PS, the first two commits are an artifact of me not knowing how to branch properly when I started this. Those are part of my "http cache headers" pull request.