bobthecow / mustache.php

A Mustache implementation in PHP.
http://mustache.github.io/
MIT License
3.25k stars 420 forks source link

HTML Minify cache template #355

Open dejurin opened 4 years ago

dejurin commented 4 years ago

How about make minify cache template how like this https://github.com/jenstornell/tiny-html-minifier possible?

bobthecow commented 4 years ago

Unfortunately it's probably not possible to solve in a general case. Mustache templates usually aren't valid HTML, so any minification will likely break :-/

dejurin commented 4 years ago

Yesterday Im was experiment with this. This can be applied when the file is cached.

Снимок экрана 2020-01-04 в 19 22 39

It would be useful to influence the content before writing to the cache.

bobthecow commented 4 years ago

But if we allow that, it's non-deterministic and we can't guarantee the sanity of the cache.

If you want to do something like this, a good place to do it would probably be in a custom loader.

dejurin commented 4 years ago

Thank u.

dejurin commented 4 years ago

I was found a very simple solution. In file Compiler.php change in function text($text, $level)

$code = sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export($text, true));

on

$code = sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export(trim($text), true));

I added only trim function, and got minify html.

Снимок экрана 2020-01-05 в 14 54 26

PS: If this solution will be test OK, your will maybe added this option?