Minication of HTML – but trought Latte parser

Notice: This thread is very old.
Jakub Bouček
Member | 54
+
+1
-

Hi,
is some possible way to minification outputed content from Latte? We can't (don't want) use some postporcessing filter of Apache (like mod_pagespeed, anyone by output-buffer, etc.).

I have idea about minify generated PHP files from Latte (in cache). I know, this method has not perfect result (some whitespaces keep between blocks, includes, etc.), but it can be good for me …and cached=zero latence.

I looked to Latte/Parser (and other) to some filter method what useable to my idea. Unsuccessfully.

Any other idea?

David Grudl
Nette Core | 8105
+
0
-

Minification of source template maybe is way…

mishak
Member | 94
+
0
-

How much would you save by using template “html” compression?

Generally is way cheaper to just enable gzip or use more data friendly format (json, bjson) and client script to show them if you are at point of considering even html compression (performance gain of that is erased by any other single extra resource that browser has to load).

I think you have to processed generated files with some heuristic that will determine what effect PHP code has. Or if you abide rule of just printing text and no printing unescaped html it can get much simpler.

IMO this is very expensive and low impact.

Last edited by mishak (2014-04-02 14:49)

amik
Member | 118
+
0
-

Hi,
I'd like to re-open this discussion. I just did few experiments on few samples and found out that randomly chosen (from my nette application) gzip-compressed minified HTML is about 5–10% smaller than the same gzip-compressed non-minified HTML. It won't improve your page load speed much, but also not so insignificant when combined with other optimalizations.

Most of not-minified whitespace is being hardcoded into HTML in original latte and needlessly transferred to compiled versions. As the template is compiled only once, eliminating insignificant whitespace during latte compilation is absolutely costless during normal page load.

Do you think this would make sense? If yes, I'm willing to implement this as addon or pullrequest to Nette as I'm currently writing an application where every performance improvement would be important and I will need it for myself. Please give any thoughts/opinions about such improvement before I start writing it.

Michalek
Member | 210
+
-4
-

@layout.latte

{block |strip}
<!DOCTYPE html>
everything else

:-)

amik
Member | 118
+
0
-

Michalek wrote:

@layout.latte

{block |strip}
<!DOCTYPE html>
everything else

:-)

I didn't know that filter:) however, it has two weak spots:

  • the replace is done at run-time, while most of whitespace could be removed at compile-time.
  • it needs to buffer the whole output to a varible and then pass it to preg_replace_callback, which may actually have worse performance impact than the improvement by minification.
Filip Procházka
Moderator | 4668
+
+6
-

@amik sure, adding it to latte would make sense to me. It should be implemented as an option on Latte\Engine, so it can be enabled using DI in configuration. That would be great :)

Last edited by Filip Procházka (2014-11-26 02:59)