Home >Web Front-end >JS Tutorial >In Js code, the reason why a random number is added after the ajax request address to prevent browser caching_javascript skills

In Js code, the reason why a random number is added after the ajax request address to prevent browser caching_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:34:341057browse

When I saw JS written by others, random parameters were 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 the browser does not send a request and reads 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 deceive the browser into changing the url, and it will send a request to the server every time without reading the cache

Statement:
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