Why add a random number after the ajax request address to prevent browser caching

亚连
Release: 2018-05-22 13:44:36
Original
2062 people have browsed it

In the Js code, a random number is added after the ajax request address to prevent browser caching. Friends who need it can refer to

When you see JS written by others, random parameters are added after the ajax request address, such as XXXX ?t= new Date().getTime().

I didn’t understand why at first, so I checked the information online. The reason is to prevent browser caching.

In order to improve the speed of users accessing the same page, the browser will cache the page data. When the url request address remains unchanged,

sometimes causes the browser to not send the request and read the previous data directly from the cache.

If the data changes without adding random numbers, the data read will be the same as before.

Adding a random number is to trick the browser into changing the url, and it will send a request to the server every time without reading the cache.

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

Related articles:

Json-lib processing solution when using frameworks such as Ajax or Easyui (graphic tutorial)

Ajax Realize the effect of infinite loading of lists and secondary drop-down options

Example sharing of using AJAX to implement progress bars on web pages

The above is the detailed content of Why add a random number after the ajax request address to prevent browser caching. 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
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!