In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to turn on gzip and deflate compression. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
What is compression?
Do you remember the first time we came into contact with winzip software? It is amazing that a file, after winzip compression, can be compressed to about 30% of its original size. I remember that at that time, many files were compressed before they could be put on their own floppy disk.
For websites, there is also such compression technology, which can slim down the text files in your web pages, effectively reduce the number of web pages through gzip and deflate compression programs, and let users open the site faster without the user's knowledge.
How useful is compression?
Through a small test software, I visited portals such as Sina and NetEase.
Access to Sina's home page:
NetEase's home page visit:
You can clearly see that the home pages of NetEase and Sina have both shrunk by more than 70% after compression.
As we all know, when a web page is reduced to 30%, the efficiency of opening the site will be tripled for the end user.
Note:
The address of the tool http://www.gidnetwork.com/tools/gzip-test.php you can also test their own site after compression.
What if the user does not support compression?
When compression is enabled, will the user fail to access the file because the user cannot access the compressed file?
No, because browsers with Trident, Gecko and Webkit kernels all tell the server what compression format they support when initiating requests, as shown below:
On the other hand, the server gives corresponding feedback according to the compression format supported by the user in the request. If there is no Accept-Enconding header in the user-initiated request header, it will be returned to the user in an uncompressed format.
How do I turn on compression?
Please Baidu Niangzhi, there are too many tutorials on the Internet, so I won't repeat them.
What content should compression be turned on?
You only need to enable compression for the domain name of the text file. Pictures, etc., are already in a compressed format, and then using compression will not reduce any file size, but will lead to a higher load on the server, as well as a variety of unexpected problems due to the irregular compression of images.
Therefore, before turning on compression, it is best to complete the domain name split, see how to make the website open the second bullet faster.
Be skillful:
When compression is enabled, it is recommended to use an apache server.
Because the IIS server has a small problem when dealing with compression, that is, when it is accessed for the first time, the file given by IIS is uncompressed, and the compressed file is given directly for subsequent access.
In fact, this small bug is not a big problem, but now many websites are using some cache servers or CDN, which will cause this problem to be magnified and compression enabled can not be completely successful.
And apache is the first time to directly give the compressed file.
Of course, if you are using IIS, and can not replace apache, then your own trouble, write a script, will be commonly used pages, after opening the compression, visit 2 times, can reduce a lot of problems.
Open the Advanced part of Compression
The current Internet situation in China
Who is in charge of the Chinese network, of course, telecom and Unicom two flowers, but now more and more see the phenomenon is a hundred flowers competing for beauty, in addition to these two flowers, more and more emergence of small ISP. Such as Mobile, Telecom, Great Wall, founder, Gehua Cable, Sinnet, and even some small operators from Hong Kong in the south.
These small operators all have a feature, that is, they can cache files. In order to reduce the bandwidth of inter-network settlement, they will try their best to cache files so that their users can access them locally.
Second, for many large and medium-sized companies, they will also build their own cache servers.
In addition, there are many websites that build or use third-party CDN, which are also cache servers.
Therefore, the current network situation in China is basically that the cache server is providing many services. So, if you turn on compression, if you do not actively cooperate with these various cache servers, then you out, you will find that a lot of your efforts are jokes, and have no practical effect.
How to adapt to the current situation? How can we ensure that when the user supports compression, the compressed file you want to give him is transferred between the network?
Then, please keep the following points in mind and implement them one by one.
When you enable compression, you need to return Vary:Accept-Encoding headers for both compressed and uncompressed files.
This header tells the cache server to provide the corresponding file according to the encoding supported by the user.
This item is very important, and many websites just open the header for compressed files. In the cache server, if the given uncompressed file does not contain the header, it tells the cache server that when the user requests, it is not necessary to judge the encoding format supported by the user, but to transfer the file directly. Therefore, when the user requests to the cache server, the uncompressed files are returned directly regardless of whether the user supports compression or not.
When you enable compression, you need to enable compression for both HTTP1.1 and HTTP1.0.
We all believe that users of the HTTP1.0 protocol, who must be very old users, certainly do not support compression, so many websites provide uncompressed files for the HTTP1.0 protocol.
However, in practice, too many cache servers are still using the HTTP1.0 protocol in pursuit of maximum compatibility. So, when you just turn on compression for the HTTP1.1 protocol, you are winking at the blind.
For example, Sina's cache server is also based on HTTP1.0 protocol, but they are smart enough to enable compression services for HTTP1.0, as shown below:
The above is the editor for you to share how to turn on gzip and deflate compression, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.