C
C
Crash2016-11-10 15:30:46
Yii
Crash, 2016-11-10 15:30:46

Is it possible to minify html in Yii1 using standard tools?

It is necessary to minify static html pages for subsequent saving of the layout in the database. How to do this in Yii, preferably by standard means?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
Crash, 2016-11-11
@Bandicoot

In general, I settled on a simple and banal
trim(preg_replace('/\s+/', ' ', $html))

N
Ne-Lexa, 2016-11-10
@NeLexa

If you use Smarty as a template engine, then there is a special tag {strip} , inside which html is minified, and plus, this happens only once during template compilation, and not with every request.
As for the standard tools, try adapting a widget from Yii2 that deals with cutting out unnecessary gaps - Spaceless .

E
Elena Stepanova, 2016-11-10
@Insolita

if the pages are generated by yii itself, then hang the behavior on this event
YII1 www.yiiframework.com/doc/api/1.1/CController#after... that
removes spaces from the view
, the function itself can be peeped in the widget mentioned above

public function minify(string $content):string
    {
        return  trim(preg_replace('/>\s+</', '><', $content));
    }

if the pages are somewhere separate, then read by regular means. process with a function and write where necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question