H
H
HAbRAhabp2015-10-31 10:30:35
PHP
HAbRAhabp, 2015-10-31 10:30:35

How to minify HTML on the fly with nginx?

So far, I'm looking for a script that would give minified HTML in a PHP file. But so that the edited file remains in a readable form. WP is full of this stuff. But the fact is that I have a self-written script. Is there anything suitable for this?
- FastCGI (Nginx 1.8 + PHP-FPM 5.6) own VPS.
I tried pagespeed, but I didn't even understand how to set it up...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2015-10-31
@HAbRAhabp

https://developers.google.com/speed/pagespeed/modu...

http {
  pagespeed On;
  pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
  pagespeed EnableFilters combine_css,combine_javascript;

  server {
    listen 80;
    server_name www.example1.com;
    root /www/example1;
    pagespeed MapRewriteDomain cdn.example1.com *example.com;
  }

  server {
    listen 80;
    server_name www.example2.org;
    root /www/example2;
    pagespeed MapRewriteDomain cdn.example2.org *example.org;
    # Don't want combine_css here
    pagespeed DisableFilters combine_css;
  }

  server {
    listen 80;
    server_name www.example3.org;
    root /www/example3;

    # mod_pagespeed off for this virtual host
    pagespeed off;
  }

A
Arman, 2015-10-31
@Arik

I don’t know about nginx, but PHP-FPM can run a php script before and after the main action. It turns out that you can run ob_start () in pre.php, collecting the output into a buffer and then in post.php, do whatever you want with the data from the github and give it to the user

I
Ilya Bosenok, 2015-11-02
@bosenok

HAbRAhabp : config in sim3x comment is not mine.
If the case, then what you need is an option:
https://developers.google.com/speed/pagespeed/modu...
Or like this:
In case you want this module to process CSS, JS (as in @sim3x example) and remove all spaces and tabs from HTML.
Please note that the documentation says that spaces inside the tags , ,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question