2

I am working on a single page application. And I have one page which makes a server requests when ever that page is loaded. I made some changes and deployed on the server. But when I am using the live version application, it's not reflecting the changes and whatever the changes I made it's updating in the database but after reloading it's again displaying the old records. This is not happening on local environment.

The next thing I tried is I deleted the cookies manually and then refresh the page. Now it's reflecting the current changes. But this one leads me to some questions.

  1. Since the request is made to the server and the records are pull out from database to display. Then why the chrome was displaying the old data ?
  2. Is it because of the cookies ? If it is then what is the solution for this kind of problem. Because for end users they might not know to delete the cookie. One fix I can think of is to delete the old cookies whenever the page is loaded but then this solution is like there is no cookie.
  3. Does it only happen in V8 ? What about spider monkey or other javascript run time environments ?

Regards

Lokesh Pandey
  • 1,739
  • 23
  • 50
  • can you check for cache – Akhil Aravind Jun 05 '18 at 06:20
  • But why the chrome is displaying the old records if the server is sending the updated data ? – Lokesh Pandey Jun 05 '18 at 06:22
  • This has less to do with JavaScript and more to do with how your service is handling HTTP requests via caching mechanisms. Unless you're using a [service worker](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API), in which case disregard the above. – Patrick Roberts Jun 05 '18 at 06:22
  • browser always look in cache first – Akhil Aravind Jun 05 '18 at 06:28
  • @PatrickRoberts Service workers helps to run the application even if it is offline. But the application is not going offline because I can see some changes in db. And also I am not using service workers – Lokesh Pandey Jun 05 '18 at 06:29
  • @AkhilAravind In that case don't you think there is a problem because no matter what I'll keep updating and the browser will always fetch the old data. And the changes will reflect after some time or I delete the cache. – Lokesh Pandey Jun 05 '18 at 06:31
  • @Lokesh use spread operator to resolve this issue – Akhil Aravind Jun 05 '18 at 06:35
  • @AkhilAravind how ? – Lokesh Pandey Jun 05 '18 at 07:00
  • You say you're caching the data, how are you doing that? How are you setting the response data, and how are you reading from the cache when you start your application? It would be easier to provide help if you could include the code related to performing the request, setting the cache, and reading from cache. Otherwise it will be almost impossible to know what's going on. – scheien Jun 05 '18 at 07:20
  • @Lokesh, please go through documentation. – Akhil Aravind Jun 05 '18 at 07:31

2 Answers2

0

It might happen because of request caching. I've definitely seen this in some browsers. You are accessing the same request url, aren't you? Try appending a random guid to the url so that it would look like "/url?guid=...".

Hirasawa Yui
  • 1,138
  • 11
  • 29
0

In ajax call, please check if cache:true is set, with true set it caches the request and displays the older response. Setting cache:false should help