In website construction or operation, especially in website optimization, we may encounter the word "gzip compression ". So what is gzip? How do I perform gzip compression?
Gzip is short for GNU zip. It is a File compression program of GNU Free Software and is often used to indicate the file format gzip. The compression efficiency is very high. Generally, the compression ratio is up to 70%. The size of a general webpage is about 40 kb. After gzip compression, only 12 KB is left. Gzip adopts common compression algorithms to compress static files such as HTML, JavaScript, and CSS and dynamic files such as ASP, aspx, PHP, and JSP. Is it good? We usually compress files. Why can't we "package" our webpage and send it to the browser for reading? Gzip has the following advantages:
Saves bandwidth resources;
Accelerate website loading.
Bandwidth saving does not matter for most websites, because many websites are small websites, especially in the Dongguan enterprise website market. Bandwidth saving is of no special use. Because the website traffic is not large.
It is necessary for most websites to speed up website loading. Why? Because the speed of opening a website is closely related to the optimization of the website, it is also in line with the user experience of the website. Visitors will certainly appreciate the high speed of opening a website. You cannot like a website that takes 8 seconds to open, right? For some websites, opening a website is slow for one second, which will reduce the turnover by at least 1%. Therefore, accelerating website loading is the greatest use of gzip.
How HTTP compression works
Gzip is a type of HTML compression algorithm. Http compression transfers compressed text content between web servers and browsers. How HTTP compression works:
After receiving the HTTP request from the browser, the web server checks whether the browser supports HTTP compression;
If the browser supports HTTP compression, the web server checks the suffix of the request file;
If the requested file is a static file such as HTML and CSS, the web server will check whether the latest compressed file of the requested file already exists in the compressed buffer directory;
If the compressed file of the request file does not exist, the web server returns the uncompressed request file to the browser and stores the compressed file of the request file in the compressed buffer directory;
If the latest compressed file of the request file already exists, the compressed file of the request file is directly returned;
If the requested file is a dynamic file such as aspx, the web server dynamically compresses the content and returns it to the browser. The compressed content is not stored in the compressed cache directory.
How do I perform gzip compression? Generally, Gzip is enabled in contol pannel, HTTP server Gzip is enabled, and PHP Gzip is used.
Both IE6 and Firefox support the client gzip. Before the webpage is transmitted, the client uses gzip to compress and then transmits the data to the client. After receiving the data, the client is decompressed by the browser and displayed.
IIS6 has built-in support for gzip compression. The gzip compression method on IIS6 is as follows:
If you need to compress static files, you can first create a new directory on the hard disk and set write permissions for the user "IUSR _ machine name. You do not need to compress dynamic files because the pages are dynamically generated every time (the pages are dynamically generated. In the IIS manager, right-click the website and choose "properties". The website is not the following site, but the whole website. Go to the "service" tab and choose to enable dynamic content compression and static content compression. The temporary directory space for gzip should be about MB.
Select the Server Extension under the website and create a new server extension. You can use any name you want. The path of the file to be added below is:
C: \ windows \ system32 \ inetsrv \ gzip. dll and enable this extension.
Static content can be compressed at this time, but for dynamic content, the aspx file is not within the compression range. We can only modify its configuration file.
There is a metabase. xml file under c: \ windows \ system32 \ inetsrv \. You can open it in notepad and find iiscompressionscheme, which has three segments with the same name,
They are
<Iiscompressionscheme location = "/lm/w3svc/filters/compression/deflate"
<Iiscompressionscheme location = "/lm/w3svc/filters/compression/gzip"
<Iiscompressionschemes location = "/lm/w3svc/filters/compression/parameters"
The first two paragraphs have basically the same parameters. Add a line of aspx under the parameters hcscriptfileextensions. If you have other dynamic programs to compress, add them here. Change hcdynamiccompressionlevel to 9, which is the most cost-effective.
So far, we have implemented the gzip compression process. Note the following: after gzip compression is enabled for a webpage, the website opening speed may not be too obvious (as opposed to the viewer). You can use some specific methods to check whether your webpage has been compressed, and compression ratio and acceleration speed.