# Compressed page streams detection and optimization

**URL:** <https://www.ruby-forum.com/t/compressed-page-streams-detection-and-optimization/246175>\
**Category:** NGINX\
**Created:** [September 12, 2013, 12:07pm UTC](https://www.ruby-forum.com/t/compressed-page-streams-detection-and-optimization/246175 "2013-09-12T12:07:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [September 12, 2013, 12:07pm UTC](https://www.ruby-forum.com/t/compressed-page-streams-detection-and-optimization/246175/1 "2013-09-12T12:07:30Z")

</div>

Hello,

I have a website serving a number of different PHP based applications.  
Some of them natively serve their own gzipped pages, others only serve  
compressed HTML but uncompressed .css and .js files, others don’t  
compress  
anything.

So far I have a per /location/ Nginx gzip configuration. Gzip is  
globally  
disabled and is explicitly enabled per location.  
The apps I need or want to be compressed by Nginx simply have this:

location /blah/ {  
include my\_gzip\_custom.conf  
}

That conf file works great for all but one web app that serves a weird  
mix  
of compressed and uncompressed pages / related files.  
What happens if Nginx gets served by PHP-FPM a compressed page and maybe  
1  
compressed .css file + 5 uncompressed .css files and 6 .js?  
Does it “spend time and resources” re-compressing the already compressed  
streams?  
Does it wrap the gzipped compressed streams inside its own compressed  
streams? (I admit my ignorance about if nested compressed streams are  
even  
supported by web standards).

Or does it - hopefully - detect an incoming stream “magic numbers” or  
headers and transparently skips re-compression / wrapping?  
That is, may I get an efficient output where Nginx only compresses the  
specific page-included files (.css etc) that required it and  
passes-through  
the already compressed contents?

If not, is it possible to implement such a mechanism by means of  
configuration and how?

Thanks in advance.

Posted at Nginx Forum:

> **[Compressed page streams detection and optimization](https://forum.nginx.org/read.php?2,242802,242802#msg-242802)**
>
> Hello, I have a website serving a number of different PHP based applications. Some of them natively serve their own gzipped pages, others only serve compressed HTML but uncompressed .css and .js files, others don't compress anything. So far I have a...

---

<div class="post-metadata">

**Author:** ![dfumagalli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@dfumagalli](https://www.ruby-forum.com/u/dfumagalli)\
**Post date:** [September 12, 2013, 1:55pm UTC](https://www.ruby-forum.com/t/compressed-page-streams-detection-and-optimization/246175/2 "2013-09-12T13:55:00Z")

</div>

Hello!

On Thu, Sep 12, 2013 at 06:07:05AM -0400, dfumagalli wrote:

[…]

> What happens if Nginx gets served by PHP-FPM a compressed page and maybe 1  
> compressed .css file + 5 uncompressed .css files and 6 .js?

[…]

> Or does it - hopefully - detect an incoming stream “magic numbers” or  
> headers and transparently skips re-compression / wrapping?

Yes, it checks if a response is already compressed based on the  
Content-Encoding header, and only compresses the response if it’s  
not. It’s usually enough to just configure/enable gzip at http{}  
or server{} level.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![dfumagalli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@dfumagalli](https://www.ruby-forum.com/u/dfumagalli)\
**Post date:** [September 12, 2013, 4:36pm UTC](https://www.ruby-forum.com/t/compressed-page-streams-detection-and-optimization/246175/3 "2013-09-12T16:36:18Z")

</div>

Thank you very much!

Posted at Nginx Forum:

> **[Re: Compressed page streams detection and optimization](https://forum.nginx.org/read.php?2,242802,242813#msg-242813)**
>
> Hello, I have a website serving a number of different PHP based applications. Some of them natively serve their own gzipped pages, others only serve compressed HTML but uncompressed .css and .js files, others don't compress anything. So far I have a...
