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

A brief discussion on the caching mechanism of Ajax

亚连
Release: 2018-05-25 13:37:28
Original
1019 people have browsed it

This article mainly introduces us to a few simple rules and precautions of the AJAX caching mechanism. It is very good and is recommended to everyone here.

The caching mechanism of Ajax is the same as the caching mechanism of the browser when processing resources.

Three simple rules:

As long as it is a GET request with the same URL, the browser will use the cache (of course it also depends on the server's Cache-Control/Expires/Last-Modified/ETag header settings) ).
As long as it is a POST request, the browser will not cache it.
Https requests will not be cached by the browser (this is the case in most cases, but there are exceptions, and it is said that FF browser is an exception).

Supplement:

Inserting a random query string into the URL can make the browser think that this is a new request and thus not use the cache.
Set the Http header in the Ajax request: If-Modified-Since:0 to tell the server to ask for new content.

Supplementary Note:

Under normal circumstances, if the user manually triggers the browser refresh (windows:F5 MacOS:command R), the browser will ignore the setting of the Cache-Control/Expires header of the resource. And go connect to the server. This is true whether it is a page refresh or an Ajax refresh.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Ajax core XMLHttpRequest summary

Solving the problem of ajax cross-domain request data cookie loss

Use ajax to change page content and address bar URL without refreshing

##

The above is the detailed content of A brief discussion on the caching mechanism of Ajax. For more information, please follow other related articles on the PHP Chinese website!

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