Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static files shown as uncompressed even when web server has been configured for gzip compression

I have hosted my website on Amazon Elastic BeanStalk. It uses nginx as proxy server and has gzip compression enabled. But when I run PageInsights on the site, it reports that many of my static content files need to be gzipped. Why is PageSpeed Insights not recognizing the compression? Is there something extra that needs to be done?

like image 873
gsrivast Avatar asked Apr 07 '14 17:04

gsrivast


People also ask

How do you check gzip compression is enabled or not?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled.

What is the work of gzip compression?

Gzip, the most popular compression method, is used by web servers and browsers to seamlessly compress and decompress content as it's transmitted over the Internet. Used mostly on code and text files, gzip can reduce the size of JavaScript, CSS, and HTML files by up to 90%.

How do I enable gzip compression on my server?

Gzip on Windows Servers (IIS Manager)Open up IIS Manager. Click on the site you want to enable compression for. Click on Compression (under IIS) Now Enable static compression and you are done!


1 Answers

I think I actully found the answer

By enabling gzip compression on nginx, you enable it only for text/html (that is nginx default http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types)

In order to enable it for other types, you have to do it explicitly. In case of beanstalk, create the following file in your project

.ebextensions/gzip.config

and put the code there (make sure you keep the indentation, it is important):

files:
  /etc/nginx/conf.d/gzip.conf:
    content: |
      gzip_types application/json;

As you can see, in my case I needed to gzip json files, you are probably having problems with Pagespeed complaining about css and js files, right? As the link above suggests you can use a * wildcard to compress everything, but if not, just list the mime types you need in the config, deploy it, and check PageSpeed Insights again.

like image 97
Dmitry Fink Avatar answered Oct 12 '22 21:10

Dmitry Fink