Web App disables the phone browser caching method

Source: Internet
Author: User
Tags browser cache

Developers have developed the Web app, especially the front-end personnel, have encountered this annoying thing, JS or CSS code changes, can be mobile browser How to refresh is not updated, mobile browser cache particularly bad.

So today put a way to solve this problem. Remember, the local debugging time affixed, on-line to delete oh, lest visitors browsing experience slow.

Code:

<meta http-equiv= "Expires" content= "0" ><meta http-equiv= "pragma" content= "No-cache" ><meta http-equiv = "Cache-control" content= "No-cache" >

Paste the above code into the head.

By the way, put a cache of data:

1. Concept

The Cache-control is used to control the HTTP cache (which may not be partially implemented in http/1.0, only Pragma:no-cache is implemented)

Format in a packet:

Cache-control: cache-directive

The cache-directive can be as follows:

The request is used:

| "No-cache" | "No-store" | "Max-age" "=" delta-seconds| "Max-stale" ["=" Delta-seconds]| "Min-fresh" "=" delta-seconds| "No-transform" | "Only-if-cached" | "Cache-extension"

Response when used:

| "Public" | "Private" ["=" < "> Field-name <" >]| "No-cache" ["=" < "> Field-name <" >]| "No-store" | "No-transform" | "Must-revalidate" | "Proxy-revalidate" | "Max-age" "=" delta-seconds| "S-maxage" "=" delta-seconds| "Cache-extension"
Section Description: Depending on whether the cache is divided into public  indicates that the response can be cached by any buffer. Private  indicates that the entire or partial response message for a single user cannot be shared with the cache. This allows the server to simply describe a partial response message for the user, and this response message is not valid for another user's request. No-cache  indicates that a request or response message cannot be cached (http/1.0 replaced with pragma no-cache) based on what can be cached No-store  used to prevent important information from being inadvertently released. Sending in the request message will make the request and response messages do not use the cache. Depending on the cache timeout Max-age  indicates that the client can receive a response that is not longer than the specified time (in seconds). Min-fresh  indicates that the client can receive a response that is less than the current time plus a specified time. Max-stale  indicates that the client can receive a response message that exceeds the timeout period. If you specify a value for the Max-stale message, the client can receive a response message that exceeds the specified value for the timeout period. Expires indicates the presence of time, allowing the client to not check (send the request) before this time, equivalent to the max-age effect. But if it exists at the same time, it is covered by Cache-control max-age. Format: Expires = "Expires" ":" Http-date for example Expires:thu, Dec 1994 16:00:00 GMT ( must be in GMT format )
2. Apply meta settings via HTTP expires and Cache-control<meta http-equiv= "Cache-control" content= "max-age=7200"/><meta http-equiv= "Expires" content= "Mon, Jul 23:00:00 GMT"/> The above settings for example, the actual use of one can. This is only valid for this page, it is not valid for pictures or other requests on the webpage, and does not do any cache. This way the client requests more, although only check the last-modified state of things, but the request for a lot of browsing speed must have an impact.
If you want to add the cache to the file via Apache's Mod_expire module, <ifmodule mod_expires.c>expiresactive onexpiresdefault "Access plus 1 Days
</IfModule> remember Expiresactive set to ON, I did not set on at first, it seems that how yslow can not find the cache mechanism. This is the default for all additions.
Apache Module mod_expires In addition, when clicked on the browser refresh, the client sends the request is Max-age=0, indicates the validate operation, sends the request to the server requests to check the cache, then updates the cache, The general get is 304 not Modified, which means no change.

 

Related Article

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.