Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Management Analysis of HTTP response header

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

HTTP response head management analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Why are you talking about HTTP head?

1. With a very simple HTTP header, you can make your users open it 10 times faster.

2. The articles about the head of HTTP on the Internet are too mysterious and professional, and are of little practical value.

3. Too many people read too many messy articles and add a lot of HTTP headers that they don't know why.

4. HTTP over will block your user access. Have you considered it? Have you considered how to make your HTTP head just enough to work without getting too bloated and blocking your users?

What is the head of HTTP?

The HTTP protocol adopts the request / response model.

The client sends a request to the server, and the request header contains the requested method, URI, protocol version, and a MIME-like message structure containing request modifiers, customer information, and content. The server responds with a status line, including the version of the message protocol, success or error coding, plus server information, entity meta-information, and possible entity content.

The above is copied, in fact, I do not want to say, hehe, but popularize it.

The following is what we talk about in this article.

Management of HTTP response header

What are the commonly used HTTP response headers?

Look at the picture:

To sum up, the common HTTP headers are as follows:

Which heads need to be well managed?

Cache-Control

This is a wonderful header, it can change your home page from 2MB to 200KB.

Yeah, that's it.

Let's take a look at what others have done after using it.

Reduced so much, the site and users win-win, rely on this head. Now I'm going to talk about how to use it.

Last-Modify

This head is easy to use, so use it. Why take it out and say it alone?

Because of this head, there is a small hidden risk. I have seen many people win the bid. I point it out, hoping that more people can see it and avoid it later.

Many websites, when updating the site or publishing temporary maintenance information, will cut the old file to another directory, and then upload a file with the same name locally for file update or page update of the site. When there is a problem with the updated page or when the maintenance ends, they use the normal page to serve the user, they will immediately cut back the old file and overwrite the old file.

There is a very big problem.

Because for people who have visited the site, they have cached the files locally. When the user visits the site again, an If-Modify-Since request is sent.

Old file Last-Modified: old time

New file Last-Modified: new time

When you replace a new file with an old file, because the new file was last modified earlier than the old file, IE will not let users get the old file without a problem, but let them use the new file.

So, if you use the old file instead of the new file, be sure to do a small deal with the old file to update the last modification time, otherwise, the user will still visit the problem page or maintain the page.

How to use Cache-Control well?

When you do not want users to cache, you only need to add a header, no-store, other no-cache, must, must-revalidate, proxy-revalidate and so on are not necessary, because no-store is generally the most advanced by default.

Other pages that allow users to cache, distinguish between directories, and configure different max-age headers according to different directories.

What is the use of max-age?

After the user gets the HTTP response header, an expiration time is formed based on the local time and the time of the max-age. For example, if you set the user's current time to 11: 00 and set to 600, then the file will expire at 11:10 after it is received. That is, this user, who accesses the file before 11:10, will directly cache the hit without making a request to the server.

Therefore, the use of max-age can make your site, like the four portals, reduced to one-tenth of its original size, and the number of requests will be greatly reduced in a short period of time.

How to set up Cache-Control?

How to set up Baidu Niangzhi.

Management suggestions:

You can't configure Cache-Control for each file, so it's best to split the domain name first and configure different cache headers for different applications (one domain name for file class, one domain name for image class, etc.).

If your website belongs to large and medium-sized websites, such as those with more than 100m web access bandwidth, different cache controllers may be configured for domain names, which can no longer meet your needs. At this time, you can manage your directory well.

Divide the files into different directories according to the characteristics of your website, and then configure different cache control headers for the directories.

How big is the max-age setting?

The following are all recommended values, but what is most suitable for you is your own cache time configuration according to the characteristics of the site.

Home page, the recommended value is 900, that is, 15 minutes.

For text class files, it is recommended to be 10800, that is, 3 hours.

For picture files, it is recommended to be 86400, that is, 24 hours.

Swf class files, recommended for 604800, that is, 7 days.

Flv, exe class files, recommended for 31536000, that is, 1 year.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report