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