Phone browser cache and Computer Browser cache problem logging

Source: Internet
Author: User
Tags browser cache

 First, the background description:

In order to optimize the Web page speed, we take js,css merge compression and control it on the server side. So I learned a bit about the principle of browser caching.

Because I don't want to use version number control, the version number has many drawbacks:

1. Modify the version number for each modification.

2. If all the pages of the reference, the version number is configured separately, then each time the amount of modification is very large;

3. If you are using the same familiar configuration for all pages to avoid the 2 problem, then every time you modify a file and update the version number, all the referenced version numbers are updated, which is silly.

Therefore, do not take version number control, using Time control, page reference does not change, the target file has changed, the server can tell the client browser.

The page uses the following method to request a CSS style file for the current page:

<link type= "Text/css" rel= "stylesheet" href= "<s:text name= ' Compressurl '/>/dynamic.css?p=dd&urls=xxx, yyy "/>

Server Processing methods:

1. Due to the use of version number, in each modification of the time to modify the version number, too troublesome, so take the server to use the file modification time control, the use of HTTP if-modified-since.

2. Detect the file modification time, and the browser pass over the if-modified-since comparison, if need to update, return 200, send the latest data to the browser;

3. If the update does not need to return 304, the browser will take the local cache, no need to consume traffic and wait for data transmission, save time and traffic (not described here, how to control the implementation of 304 and 200)

second, there are problems

PC-side browser: all normal, achieved the original purpose: The style file is not updated to return 304, the browser continues to use the cache;

The next time the style file is updated, when the client browser requests it, it will get 200 return value and receive the new file;

mobile phone with browser/inside browser: Some mobile phone line, some phones do not. The behavior is: the first request to cache the style file locally, the second style file modified he did not update.

I use a number of mobile phone testing, found that when the server file changes, Xiaomi 2S mobile phone can be updated in a timely manner, colleague Samsung model can be timely to get the latest documents, and the iphone and Huawei do not.

The test concludes: iphone and Huawei's mobile phone after the first visit to the Web page, the style file cache, the second direct no change (in fact, there is no request to the server, did not ask the server to update)

That is: 1. The first time the computer to download the file , each time each will ask the server is updated, 304 is not updated, 200 updates (can be fully controlled on the service side)

2. Some mobile browser and browser, only in the first visit to download the file, as long as the URL does not change, in the future there is no re-request (may be the browser in order to give province traffic, and speed up);

Iii. Solutions

If it is computer-side use, I this solution, no problem, with very cool;

If it is a mobile phone access, or add version number, I was not a problem with the version number, so it was not adopted, it is no way, only to make the URL change that silly browser to send a request, to get new files.

 

Phone browser cache and Computer Browser cache problem logging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.