Ever thought about automatically compressing and optimizing whitespace, CSS, JS, tracking scripts, etc.pp. without the need to write and NGINX-wire your own program?
The good news is: PageSpeed does all for you. It’s able to leave a defined ratio of all requests untouched, e.g. 50/50. So even search enginges would be happy with the original content, as they don’t like too much compression and content or whitespace reduction in pages or scripts.
Download, compile & configure the NGINX pagespeed module: ngx_pagespeed module.
There are a lot of configuration options for the NGINX pagespeed module. Have a look at the sample configurations.
Please keep in mind: the PageSpeed NGINX module is in beta state as of now, and not as stable as a final version. But it definitely minimizes headache based on slow loading times on high server load in combination with a full blown caching solution (nginx own caching mechanism, memcached, varnish, …). Haven’t tried the Apache PageSpeed module, maybe it’s a bit more stable?