undefinedfix
Sign in

Can nginx gzip be cached?

pazhitnov edited in Fri, 23 Sep 2022

If many requests are for the same file, do you need to compress each request? I think that after the first compression, there should be a backup on the server. The next time there is a request, the gzip content of the backup should be returned directly. How to set it? thank you

1 Replies
user14801358
commented on Fri, 23 Sep 2022

Using gzip in nginx_ Static to cache gzip files

Gzip static module of nginx (using -- with HTTP)_ gzip_ static_ Module compiles nginx. It allows you to pre cache your gzip files. You can use nginx - V to check which modules are included in the compilation.

Suppose you have a file / css / a . css。 When you meet a . CSS request. The static gzip module will find / css / a . css . gz。 If it is found, it will provide the file as gzip compressed content. This allows you to use the highest compression ratio (gzip) when deploying your site - 9) Gzip the static file. Nginx has absolutely nothing to do but provide static gzip files (it's very good at providing static content).

Whether you have gzip in nginx configuration, you can:

gzip_static on;
Note that you must create your own. GZ version of the file, and mention in the document that it would be better if the original file and. GZ file have the same timestamp. So it might be a good idea to "touch" the file after creating it. Reduce gzip compression (gzip)_ comp_ Level 1.. 3) is also a good idea. This minimizes compression of dynamic content without putting too much pressure on the server. Remember, this only applies to static content (CSS, JavaScript, etc.). Dynamic pages can and should be compressed, but the compression rate is low to maintain the load capacity of the server.

Webpack can output content directly to . GZ format, so working with webpack will be a good choice.