Example of how to disable caching of js files

WBOY
Release: 2016-07-25 09:12:47
Original
1182 people have browsed it

Disable js file caching, as follows: 1. Add: where the JS file is referenced:

  1. //Modified on August 14, 2009
  2. var now=new Date();
  3. var number = now.getYear().toString()+now.getMonth().toString()+now. getDate().toString()+now.getHours().toString()+now.getMinutes().toString()+now.getSeconds().toString();
  4. document.write("");
  5. //alert("");//Test
Copy code

similar to this form: js/YearReportLuRu.js?20100408154456, so that the browser will think that the js files referenced are different each time. Of course, YearReportLuRu.js does not process the subsequent dynamic numbers.

2. Just add: to the file header of the client page:

Copy the code

Server side:

  1. Response.Buffer = true;
  2. Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
  3. Response.Expires = 0;
  4. Response.CacheControl = "no-cache";
Copy the code

This method has been used in the program, but some users still have caching problems, and I personally feel that it has not been finally solved.

Other methods: The server needs to be set to allow caching, so that the client will cache some static files (such as js, css, pictures) according to the client's settings. In IIS, you can set "Enable content expiration" in the "HTTP header" of the site properties to control the client cache time. (As shown below) In this way, the HTTP header returned by HTTP is 304. Enabling caching can greatly improve the user experience. It is also recommended to enable http compression to optimize the website.

As shown below: Example of how to disable caching of js files

This method is set on the WEB publishing server.

Summary: Static files can be achieved with IIS or other WEB SERVERs. Caching the client is a mechanism problem of IE or other clients. Many users still have trouble clearing the client's cache. They can use programs to control cache problems.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!