Home Web Front-end JS Tutorial JS method to clear IE browser cache_javascript skills

JS method to clear IE browser cache_javascript skills

May 16, 2016 pm 05:27 PM
js Clear

Automatically clear IE cache method in js— Commonly used

For dynamic files, such as index.asp?id=... or index.aspx?id=... I trust experienced programs Everyone knows how to prevent browsers from caching data.
But for static files (css, jpg, gif, etc.), under what circumstances do we need to prohibit browsers from caching them, and how to do it?

Method 1: We can use a simple method to complete it in Dojo: the preventCache attribute is included in dojo.xhrGet (including post) and other methods. The meaning of this attribute: "The browser cache is enabled by default, otherwise it will be passed Automatically add different parameters to ensure browser cache invalidation" We only need to assign this attribute to: "true".

Method 2: document.write("
The 113 of ver=113 is the version number, which is generally a development version number generated by CVS or other tools.
This truly caches static files when they should be cached, gets the latest version when the version is updated, and updates the cache
for images to effectively utilize and update the cache.

js. Clear browser cache 2

In order to reduce the network transmission pressure between the browser and the server, static files, such as js, css, and modified pictures are often cached, that is, the HTTP of these files Add the Expires and Cache-Control parameters to the response header, and specify the cache time, so that the browser will not issue any HTTP requests to the server (except forced refresh) within a certain period of time, even if the server's js or css or images are displayed during this period. The file has been updated many times, but the data in the browser is still the old data that can be cached initially. Is there a way for the browser to get the latest modified data?

Yes, the method is to use ajax Request the latest file from the server, and add the request headers If-Modified-Since and Cache-Control, as follows:
Copy code The code is as follows :

$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
beforeSend :function(xmlHttp){
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.setRequestHeader("Cache-Control","no-cache");

}
});

jquery is used here.

This way the browser will replace the old local file with the latest one. Of course, another problem here is that js must know which js, css, and pictures have been updated by the server. This can be solved by using cookies and time versions.

jquery has ifModified and cache parameters since 1.2, so you don’t need to add them yourself. header

ifModified Boolean Default: false
Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.
cache Boolean Default: true
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.


$.ajax({
type: "GET",
url: "static/cache. js",
dataType: "text",
cache:false,
ifModified :true
});

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

How to completely remove viruses from mobile phones Recommended methods to deal with viruses in mobile phones How to completely remove viruses from mobile phones Recommended methods to deal with viruses in mobile phones Feb 29, 2024 am 10:52 AM

After a mobile phone is infected with a certain Trojan virus, it cannot be detected and killed by anti-virus software. This principle is just like a computer infected with a stubborn virus. The virus can only be completely removed by formatting the C drive and reinstalling the system. , then I will explain how to completely clean the virus after the mobile phone is infected with a stubborn virus. Method 1: Open the phone and click "Settings" - "Other Settings" - "Restore Phone" to restore the phone to factory settings. Note: Before restoring factory settings, you must back up important data in the phone. The factory settings are equivalent to those of the computer. "It's the same as formatting and reinstalling the system". After the recovery, the data in the phone will be cleared. Method 2 (1) First turn off the phone, then press and hold the "power button" + "volume + button or volume - button" on the phone at the same time.

How to use JS and Baidu Map to implement map click event processing function How to use JS and Baidu Map to implement map click event processing function Nov 21, 2023 am 11:11 AM

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to free up WPS cloud document space How to free up WPS cloud document space Feb 24, 2024 pm 06:12 PM

How to clear WPS cloud document space when it is full. With the rapid development of cloud technology, more and more people are beginning to use cloud storage to store and manage their files. Among them, WPS Cloud Document, as an intelligent office software, is very popular among users. However, as the usage time increases and files accumulate, the storage space of WPS cloud documents may be filled up. So, when the WPS cloud document space is full, how should we clear it? Next, we will introduce some common cleaning methods to you. The first method is to completely delete unwanted files. W

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

How to completely remove the word you want to search on Douyin? Can it be turned off? How to completely remove the word you want to search on Douyin? Can it be turned off? Mar 19, 2024 pm 12:40 PM

In today's information age, social media has been integrated into people's daily lives and has become an indispensable part. As one of the most popular short video applications, Douyin attracts hundreds of millions of users to watch and share a variety of interesting video content on its platform every day. However, Douyin’s “guess what you want to search” function has caused trouble for some users. This feature uses personal data analysis and algorithms to recommend content, sometimes showing videos that are relevant to users’ interests but not what they really want to see, causing users to feel uncomfortable or confused. Some users worry that such personalized recommendations may invade their privacy or mislead their viewing experience. Although the "guess what you want to search" function is designed to provide a more personalized one, how do you completely remove the words you want to search on Douyin? You can try clearing TikTok

See all articles