Hello, welcome toPeanut Shell Foreign Trade Network B2B Free Information Publishing Platform!
18951535724
  • How to optimize your website through the gzip

       2026-04-22 NetworkingName1410
    Key Point:Wait, why are we opening the gzip compressionBefore i do, i need to explain the code. When you want to request a document on the internet, e. G. Http://www. Yahoo. Com/index. HTML, your browser and server have a session, as shown below。Browser: hey, give me an index. HTML file server: ok, let me find it at the ~ server: found it, i'll return to a successful status code (200 ok), i'm sending files ... Browser: 100kb? Oh, god, wait, wait, wa

    Wait, why are we opening the gzip compression

    Before i do, i need to explain the code. When you want to request a document on the internet, e. G. Http://www. Yahoo. Com/index. HTML, your browser and server have a session, as shown below。

    How to optimize the website

    Browser: hey, give me an index. HTML file server: ok, let me find it at the ~ server: found it, i'll return to a successful status code (200 ok), i'm sending files ... Browser: 100kb? Oh, god, wait, wait, wait, wait, wait

    Of course, actual requests and agreements would be more formal。

    But it came into effect, and i got the index. HTML file。

    What's the problem now

    Well, the system is normal, but it's too inefficient. Frankly, 100 kb is a big text, HTML is redundant, each,

    There's almost the same closed label. Although the text is repeated, as long as you cut off anything, HTML (and one of its fellow mothers xml) will not be shown properly。

    What good is a file when it's too big? It's gzip to compress it。

    If we transmit a zip file instead of the original big file to the browser, we save bandwidth and download time. When the browser can download the zip file, depress it and render it to the user. Downloads are quick, pages are loaded, users are very good. This browser-server session is probably purple:

    How to optimize the website

    1. Browser: hey, give me an index. HTML. Can i have a compressed version if i have one

    Server: allow me to look... Well, meet you, if you find the gzip format

    3. Server: yep, found, compressing, transmitted to you immediately。

    Browser: excellent. Only 10 kb. I'll decompress and render it to users。

    It is simple: the smaller the document, the faster it is downloaded and the better the user feels。

    Don't you believe me? The HTML part of yahoo's home page is pressed from 101 kb to 15 kb:

    It's a sad, cool reality

    Part of the change is in browsers and servers, which successfully sent a compressed file in the past. There are two points to the gzip compression:

    If the server does not return the headline information of content-encoding, this means that the file is not compressed (the browser can directly interpret). The request is only a browsing request, not an order. If the server does not return the compressed file, the browser has to process the large source file。

    Server settings

    The good news is we can't control the browser. He issued “accept-encoding: gzip, deflat” or did not, and the head of the request was there, without loss。

    All we need to do is configure the server and get it back to the compressed version. If the browser controls, we can save bandwidth for everyone。

    For iis servers, start compression in settings。

    If you use nodejs to build servers like me, you win. Nodejs opens the gzip very simple, just add two lines of code。

    Const=I'm sorryI'm sorry'express♪ i'm sorry ♪;ConstApp = express();/express framework, the front must be all necessary, i. E. Just install the content component and add two sentences
    ConstCommon =I'm sorryI'm sorry'commpression♪ i'm sorry ♪;
    i don't know, app.It's a good idea(communication());

    For the apache server, we can start the compression output, and it's simple and straightforward. Add the following code to your. Htaaccess file:

    ♪ compress text, HTML, javasCript, css, xml:Addoutputfilterbytype deflateText/ plain
    addoutputfilterbytype deflateText/HTML
    addoutputfilterbytype deflateText/xml
    addoutputfilterbytype deflateText/css
    addoutputfilterbytype deflateApplication/xml
    addoutputfilterbytype deflateApplication/xHTML+xml
    addoutputfilterbytype deflateApplicationI'm sorry. Addoutputfilterbytype deflateApplication/javasCript. Addoutputfilterbytype deflateApplicationThis post is part of our special coverage global voices 2011CriptOr, companies certain data types by example:
    Setoutputfilter deflate

    The apache server has two compression options:

    Deflate faster, so i use it; of course, if you want to get better, use the mod gzip. Whatever you choose, apache will check if the browser sends "accept-encoding" the header is requested to determine whether to return the compressed file or the source file. However, some old versions of browsers cause problems and require special instructions to correct them。

    If you can't change your. Htaaccess file, you can use php to return the compressed content, give your HTML file a. Php file and add the next file to the top of the file。

    In php:

    If(substr count)$ server[`http accept encoding', `gzip')] ob start (“ob gzhandler”);I'm sorry, elseOb start();♪ it's all right ♪

    We will check the "accept-encoding" head and return the gzip compressed version of the file (or return the source file). It's like building your own web server. If you're actually building a server, use apache to compress your files. You certainly don't want to download your file。

    That's kind of an ad for apace

    Validate compression effects

    Once you have your server installed, check if he's effective。

    - online viewing: oNline gzip test to check if your web page is really compressed。

    - browser view: at the chrome google browser, f12 opens the developer's tool – > network pagemarks (fire fox and ie browser are similar). Refresh your page and click this network information. This "content-encoding: gzip" headline means it's coming down。

    How to optimize the website

    Read more by clicking on the expression "uselargerows". Contains the size of the compressed file and the size of the source file。

    How to optimize the website

    Amazingly, the home page has been reduced from 187 kb to 59 kb。

    Try some little chestnuts

    I made a few pages and a download demo:

    -index. HTML - default compression

    -index. Htm - compress *. Htm by adding *. Htm files on apache

    -index. Php — compress by php header

    Download these files, drop them on your server, adjust your server settings。

    Warning

    The gzip compression is so encouraging, but there are three other points of attention:

    - low-end browsers: some browsers still have problems receiving compressed files (they say they can, but they can't), and if your site must be on the windows95 webscape 1. 0 browser, you may not want to compress files. Apache mode deflate has set a number of neglected rules for the old browser。

    - documents that have been compressed: most pictures, music and videos have been compressed, so don't waste time compressing them. In fact, you can just compress the three giantsCript。

    - cpu load: compressing documents during transmission is cpu-intensive but saves bandwidth (space for time). Usually, the choice of compression rates requires a trade-off of advantages and disadvantages. There are also some methods of pre-compressing static documents, but this requires additional resources. Taking into account the cost of cpu, compressing documents would be more beneficial than bad. Better user experience through compression, shorter white time, value

    Opening the gzip compression is one of the fastest ways to optimize the website. Use it boldly and make your users feel better。

     
    ReportFavorite 0Tip 0Comment 0
    >Related Comments
    No comments yet, be the first to comment
    >SimilarEncyclopedia
    Featured Images
    RecommendedEncyclopedia