Sorry, this series should have been written for a long time. But after I wrote two chapters, my website crashed, the cause of the crash is that someone tried to capture data from my website, which caused frequent access to the website database. If you have read some of my previous articles, it should be known that this will also cause too many cached files on the server, because I am using a virtual host, so the server will crash. Therefore, I think this system is still flawed, so I have not introduced it for the time being (of course it has not improved much now). After the Spring Festival, I began to look for a job after the Spring Festival, I have never been in the mood to write this, so I have been dragging on for a long time. Now, I am sorry. I decided to finish introducing this system, regardless of whether it is perfect or not.
In my opinion, website production is actually a very fine thing, but after it is too fine, the development costs will increase, however, because many websites do not need such fine-grained websites, many technologies are not taken seriously. When hardware is restricted (especially for large websites ), these technologies need to be used seriously. The cache and HTTP status code are examples. After all, I think most pages are allowed to have some latency.
Cache is the cache technology of the browser. You must be familiar with it. Every time you load a file, the browser will go to its own cache folder to check whether there is any available cache. If yes, instead of downloading from the server, you can directly use the local content. This is a good way to save server performance and traffic. When the website does not have any settings, the browser determines whether to use the cache based on the user's settings. You can see the "Settings" section of the "browsing history" section of the "Internet Options" of the browser.
Generally, there are two ways to set cache: the first is to set in the head of the HTML content:
<Meta http-equiv = "expires" content = "0"> // set the file expiration time to 0 seconds.
<Meta http-equiv = "cache-control" content = "no-Cache"> // This setting indicates that the file cannot be cached.
The second type is set through HTTP head, for example, in. Net (C:
Response. cache. setexpires (time); // set the file expiration time to the current time.
I personally prefer HTTP head settings, because I think this does not belong to HTML content. Of course, if it is a static file, it can only be set through HTML head, in my website "Geographic Name Information System", I set that each HTML page fails after 7 days because the HTML is automatically generated.
In the cache introduction above, we mentioned that when a browser has a cache, it does not take the relevant content from the server. However, this setting only seems like sometimes these browsers still request data from the server, sometimes the request is reasonable. For example, when a user clicks the "refresh" button, sometimes I do not know why. Therefore, I further use the HTTP status code in the system.
Many users are reluctant to understand the HTTP Status Code. In fact, this is very important. For more information about how to use the HTTP status code and detailed instructions, see relevant documents, here are a few examples:
1. some users display their own page when the website page does not exist, but forget to use the 404 status code, so that the browser does not know whether the downloaded content is normal or the page does not exist, the user may be able to identify the page content, but the search engine robot will not, so it may be blacklisted by the search engine as "unsearchable.
2. When the page turns, the status code 301 or 302 is not used, causing the search engine to know that the leaf area has been switched.
Specifically, I want to talk about 304, which is the same as the cache. the status code indicates that "the server is not updated", that is, the file version of the client is the latest, its usage is as follows:
1. When the user requests the file for the first time, the last modification date of the file is sent to the client through the last-modified field of the HTTP head to let the client know the version of the file, for example:
Last-modified: Tue, 08 Apr 2008 14:48:05 GMT
2. when the browser requests the file again, it will automatically take the time as the content of the IF-modified-since field of the requested HTTP head (sometimes depending on the browser, the number of bytes attached to the file may be separated by commas (,). For example:
If-modified-since: Tue, 08 Apr 2008 14:48:05 GMT
3. the server determines whether the client file has expired based on the content of the IF-modified-since field (if this field exists). If it has expired, it returns a new file. If it does not, you only need to return the 304 status code to end the output. This indicates that the file version on the browser side is the latest and does not need to return the file content.
You need to know that the time for the server to return a 304 error is much smaller than the time for returning the entire file, and the performance loss and network occupation are also much smaller.
The cache and 304 technologies have already been used. I chose cache and 304 technologies to work together because the single-use cache seems like the browser sometimes gets the latest content (especially when users click the refresh button ), when you use 304 separately, the browser still takes a certain amount of time and performance to ask the server. The combination of the two technologies is just right.