-2

My application uses the Gin Web Framework for various tasks, one of which is serving static files (Vue.js). In regular intervals calls get made to this API which then updates the data in the DB. This data gets displayed through those static files. My current workaround is setting a timer function in the Vue.js part which refreshes the page every minute.

Is there any more elegant way to immediately refresh those static files as soon as the API makes a change to the DB? Or am I maybe approaching this in a completely wrong way?

kaiyonami
  • 3
  • 2

1 Answers1

0

This works by making your page in such a way that

i) It can handle data dynamically, add/update data if page receives new data

ii) Mechanism to receive data without page refresh this can be done in few ways mentioned below

  1. I can think of setting up a websocket listening for events on page with updated data like 'EventNewData' with Payload containing data which you can fetch on client and make changes to vue data object

  2. You can skip the page refresh part and make API to fetch data on page, so now instead of page refresh you will be doing a ajax request and can make a smoother user experience. This will use a interval function like you were using without page refresh

  3. You maybe can use HTTP long polling for data updates in which client polls the server requesting new information. The server holds the request open until new data is available. Once available, the server responds and sends the new information.

Shubham Srivastava
  • 1,807
  • 1
  • 10
  • 17