Home > Web Front-end > JS Tutorial > body text

Code to disable caching of js files_javascript tips

WBOY
Release: 2016-05-16 18:30:08
Original
1090 people have browsed it

As follows:
1. Add the following where you quote the JS file:

Copy the code The code is as follows:

//Modified on August 14, 2009
var now=new Date();
var number = now.getYear().toString() now. getMonth().toString() now.getDate().toString() now.getHours().toString() now.getMinutes().toString() now.getSeconds().toString();
document.write ("");
//alert("< script language="javascript" type="text/javascript" src="js/YearReportLuRu.js?" number "">");//Test

Similar to this In the form: js/YearReportLuRu.js?20100408154456, the browser will think that the js file referenced is different each time. Of course, our YearReportLuRu.js does not process the subsequent dynamic numbers.

2. Just add:
Copy code The code is as follows:

<%--No cache settings--%>




Server side plus:
Copy code Code As follows:

Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response. CacheControl = "no-cache";

I have applied this method in the program, but some users still have caching problems, and I personally feel that it has not been finally solved.
3. There are other methods. I have not used them myself in this summary. I just found them online, as follows:
You need to set up caching on the server, so that the client will cache according to the client's settings. Some static files (such as: js, css, pictures).
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)
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.

This method is set on the WEB publishing server.

Summary: For static files, you can use IIS or other WEB SERVERs. Caching the client is a mechanism problem of IE or other clients.
Popular users still won’t clear the client’s cache. So we can use programs to control caching issues.
Related labels:
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