incubator-pagespeed-ngx icon indicating copy to clipboard operation
incubator-pagespeed-ngx copied to clipboard

document gzip, gzip_static, brotli and brotli_static

Open adrelanos opened this issue 4 years ago • 2 comments

Documentation is at the moment a bit sparse on nginx gzip. Specifically nginx gzip_static.

It is my understanding that gzip_static cannot be easily used in conjunction with nginx pagespeed. Source: testing myself and this blog post.

I guess the way the architecture works is that nginx pagespeed needs/fetches the resource without compression, optimizes it and then adds its own dynamic gzip compression? The gzip compression might even be static once nginx pagespeed has cached the resource?

Perhaps worth mentioning in pagespeed documentation that gzip_static is not worth bothering with when using nginx pagespeed?

This blog post indicates that it's possible to get quasi gzip static. Perhaps you could shed some light on that?

Also can't find any mentions of brotli / brotli_static.

related google search terms:

site:https://www.modpagespeed.com gzip site:https://www.modpagespeed.com gzip_static site:https://www.modpagespeed.com brotli site:https://www.modpagespeed.com brotli_static

adrelanos avatar Jun 08 '20 19:06 adrelanos

For gzip_static, I think it matters if the origin involved is low latency and high bandwidth or far off. Concretely, if a hypothetical ngx_pagespeed enabled proxy runs in front of a far-away origin with limited bandwidth and high latency, then gzipping static content could make sense. On the other hand, if both reside in the same datacenter -- or even process, then the extra cycles spent on compressing/decompressing might not make a lot of sense sense.

So given the above, instead of a generic recommendation, I'd be more in favor of describing such scenarios in our docs.

It's also worth mentioning that regardless of nginx's configuration, pagespeed modules cache compressed versions for serving for resources where that makes sense.So I think gzip_static primarily applies to what happens when pagespeed fetches it's input resources. That leaves the case for serving static html. ngx_pagespeed will enable dynamic gzip compression when gzip isn't configured in nginx, as the static html by definition no longer is static when it flows through a pagespeed module.

oschaaf avatar Jun 08 '20 20:06 oschaaf

Also can't find any mentions of brotli / brotli_static. @Lofesa mentioned and did some explanation of how to get brotli working in nginx with the PS module in this post.

@Lofesa

About your config: pagespeed HttpCacheCompressionLevel 9; This line makes pagespeed to store optimized resources gziped, and serve it as gzip. To serve it with brotli compression you need to set it to 0, then optimized resources are stored w/o compression and brotli compress it on the fly.

So it sounds like to get brotli working, you just need to disable gzip in your pagespeed configuration with pagespeed HttpCacheCompressionLevel 0;

Danrancan avatar Mar 12 '22 20:03 Danrancan