search
HomeWeb Front-endHTML Tutorial发现nginx配置gzip,压缩css,不压缩js,原来是不压缩临界值,大于1000K的才压缩导致没有被gzip压缩。_html/css_WEB-ITnose

背景:发现并没有压缩,查来查去是这个配置有问题写成1000k了,也就是下面这些列表都不符合条件,不给gzip压缩,gzip_min_length   1k; 不压缩临界值,大于1K的才压缩,一般不用改,被修改成1000k了,于是没有压缩,查了老半天content-type,都写了,呵呵。

修改后,在这儿测试了一下,果然压缩了:

http://pagespeed.webkaka.com/youhua/gzip/

网址 http://www.justwinit.cn/template/trielegant/styles.css 的检测结果:

是否压缩  是

压缩类型  gzip

原文件大小  8704 字节

压缩后文件大小  4275 字节

压缩率  50.88%

图片是否需要启用GZip压缩?

无意间看到有网友提及,图片不用GZip压缩的。图片尽量不要使用gzip,因为gif,png等图片本身就是被压缩过的,

开启和关闭图片GZip压缩后,网页的总体积是不同的,令人惊讶的是开启图片GZip压缩后,网页总体积竟然变大了。而耗时也相应的增多了。

===========================================

1、Vim打开Nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

2、找到如下一段,进行修改

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

#gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

gzip_vary off;

gzip_disable "MSIE [1-6]\.";

3、解释一下

第1行:开启Gzip

第2行:不压缩临界值,大于1K的才压缩,一般不用改

第3行:buffer,就是,嗯,算了不解释了,不用改

第4行:用了反向代理的话,末端通信是HTTP/1.0,有需求的应该也不用看我这科普文了;有这句的话注释了就行了,默认是HTTP/1.1

第5行:压缩级别,1-10,数字越大压缩的越好,时间也越长,看心情随便改吧

第6行:进行压缩的文件类型,缺啥补啥就行了,JavaScript有两种写法,最好都写上吧,总有人抱怨js文件没有压缩,其实多写一种格式就行了

第7行:跟Squid等缓存服务有关,on的话会在Header里增加"Vary: Accept-Encoding",我不需要这玩意,自己对照情况看着办吧

第8行:IE6对Gzip不怎么友好,不给它Gzip了

上面摘自:http://www.veryhuo.com/a/view/51706.html

http://www.webkaka.com/blog/archives/how-to-set-gzip-for-js-in-Nginx.html

https://segmentfault.com/q/1010000000585128

查询是否被zip压缩:

http://pagespeed.webkaka.com/youhua/gzip/

输入:

http://www.justwinit.cn/images/js/common.js?jsver=2.1.1.3626.3

=======================================

启用Gzip  可减少 54.2 KB 启用服务器Gzip,可以减少传输字节数。更多  -3分

未启用Gzip的资源有:

http://www.justwinit.cn/template/trielegant/styles.css (大小: 8.5 KB 预计可减少 5.9 KB )

http://www.justwinit.cn/images/js/common.js?jsver=2.1.1.3626.3 (大小: 20.3 KB 预计可减少 14.8 KB )

http://www.justwinit.cn/lang/zh-cn/jslang.js?jsver=2.1.1.3626.3 (大小: 3.7 KB 预计可减少 2.1 KB )

http://www.justwinit.cn/images/js/ajax.js?jsver=2.1.1.3626.3 (大小: 7.4 KB 预计可减少 6.0 KB )

http://www.justwinit.cn/images/js/swfobject.js?jsver=2.1.1.3626.3 (大小: 6.4 KB 预计可减少 4.2 KB )

http://www.justwinit.cn/images/css/SyntaxHighlighter.css (大小: 3.6 KB 预计可减少 2.5 KB )

http://justwinit.cn/favicon.jpg (大小: 1.9 KB 预计可减少 793 B )

http://js.users.51.la/4950674.js (大小: 1.9 KB 预计可减少 1.1 KB )

http://www.justwinit.cn/images/hl/shCore.js (大小: 9.5 KB 预计可减少 5.7 KB )

http://www.justwinit.cn/images/hl/shBrushPhp.js (大小: 3.7 KB 预计可减少 2.1 KB )

http://www.justwinit.cn/images/hl/shBrushJScript.js (大小: 937 B 预计可减少 437 B )

http://www.justwinit.cn/images/hl/shBrushJava.js (大小: 1.0 KB 预计可减少 494 B )

http://www.justwinit.cn/images/hl/shBrushSql.js (大小: 1.9 KB 预计可减少 964 B )

http://www.justwinit.cn/images/hl/shBrushCss.js (大小: 4.0 KB 预计可减少 2.2 KB )

http://www.justwinit.cn/images/hl/shBrushCpp.js (大小: 2.7 KB 预计可减少 1.4 KB )

http://www.justwinit.cn/images/hl/shBrushPython.js (大小: 4.7 KB 预计可减少 2.5 KB )

http://www.justwinit.cn/template/trielegant/images/logo_header.png (大小: 5.6 KB 预计可减少 237 B )

http://www.justwinit.cn/template/trielegant/images/long.gif (大小: 924 B 预计可减少 358 B )

http://justwinit.cn/template/trielegant/images/bridge-banner-eleven.jpg (大小: 18.9 KB 预计可减少 354 B )

http://icon.51.la/icon_0.gif (大小: 846 B 预计可减少 101 B )

http://eiv.baidu.com/hmt/icon/21.gif (大小: 1.1 KB 预计可减少 69 B )

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Versatility of HTML: Applications and Use CasesThe Versatility of HTML: Applications and Use CasesApr 30, 2025 am 12:03 AM

HTML is not only the skeleton of web pages, but is more widely used in many fields: 1. In web page development, HTML defines the page structure and combines CSS and JavaScript to achieve rich interfaces. 2. In mobile application development, HTML5 supports offline storage and geolocation functions. 3. In emails and newsletters, HTML improves the format and multimedia effects of emails. 4. In game development, HTML5's Canvas API is used to create 2D and 3D games.

What is the root tag in an HTML document?What is the root tag in an HTML document?Apr 29, 2025 am 12:10 AM

TheroottaginanHTMLdocumentis.Itservesasthetop-levelelementthatencapsulatesallothercontent,ensuringproperdocumentstructureandbrowserparsing.

Are the HTML tags and elements the same thing?Are the HTML tags and elements the same thing?Apr 28, 2025 pm 05:44 PM

The article explains that HTML tags are syntax markers used to define elements, while elements are complete units including tags and content. They work together to structure webpages.Character count: 159

What is the significance of <head> and <body> tag in HTML?What is the significance of <head> and <body> tag in HTML?Apr 28, 2025 pm 05:43 PM

The article discusses the roles of <head> and <body> tags in HTML, their impact on user experience, and SEO implications. Proper structuring enhances website functionality and search engine optimization.

What is the difference between <strong>, <b> tags and <em>, <i> tags?What is the difference between <strong>, <b> tags and <em>, <i> tags?Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

Please explain how to indicate the character set being used by a document in HTML?Please explain how to indicate the character set being used by a document in HTML?Apr 28, 2025 pm 05:41 PM

Article discusses specifying character encoding in HTML, focusing on UTF-8. Main issue: ensuring correct display of text, preventing garbled characters, and enhancing SEO and accessibility.

What are the various formatting tags in HTML?What are the various formatting tags in HTML?Apr 28, 2025 pm 05:39 PM

The article discusses various HTML formatting tags used for structuring and styling web content, emphasizing their effects on text appearance and the importance of semantic tags for accessibility and SEO.

What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?Apr 28, 2025 pm 05:39 PM

The article discusses the differences between HTML's 'id' and 'class' attributes, focusing on their uniqueness, purpose, CSS syntax, and specificity. It explains how their use impacts webpage styling and functionality, and provides best practices for

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools