How to deflate js file in nginX?

Im looking for "how to compress js file load time" and I am trying to solve the question problem (Im using Extjs).

My friend offers this one . But it uses Apache as a web server. Does anyone know how to do the trick in NGINX ??

My hosting uses nginx as a web server, and I know nothing about setting up a web server.

sorry if my english is bad.

+10
nginx compression
Feb 27 2018-11-11T00:
source share
3 answers

If you do not know anything about setting up a web server, I assume that you also do not know how and where to edit the configuration file.

The nginx /etc/nginx/nginx.conf file is located in /etc/nginx/nginx.conf (checked in Ubuntu 12.04)

By default, the nginx gzip module is enabled. Therefore, check this service, whether it is enabled on with an online tool like this .

If it is disabled, add this before the server name {...} in nginx.conf

 # output compression saves bandwidth gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 6; gzip_proxied any; gzip_types text/plain text/html text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml; # make sure gzip does not lose large gzipped js or css files # see http://blog.leetsoft.com/2007/07/25/nginx-gzip-ssl.html gzip_buffers 16 8k; # Disable gzip for certain browsers. gzip_disable "MSIE [1-6].(?!.*SV1)"; 
+38
Feb 27 '11 at 9:38
source share

I am doing this configuration in my nginx.config, you need

 gzip on; location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { gzip_static on; expires 1w; add_header Cache-Control public; add_header Last-Modified ""; add_header ETag ""; } location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg)$ { gzip_static on; expires 1w; add_header Cache-Control public; add_header Last-Modified ""; add_header ETag ""; } 

+1
Mar 04 '16 at 13:05
source share

You need to use nginx HTTP gzip or nginx HTTP gzip static module. A static module would be useful for content such as your JavaScript libraries, which rarely change, which eliminates the need for re-compression for each client.

0
Feb 27 '11 at 7:51
source share



All Articles