Home >Web Front-end >JS Tutorial >A brief discussion on the caching mechanism of Ajax
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!