How should front-end UI be updated when making changes to the database via the UI?

Seeking to optimize the process of updating UI and database values at the same time.

The Scenario

Currently, there is a table displaying items with columns like ID, Name, Create Date, and Favorite button on the front end. This data is fetched from the database using axios during page load. The favorite button allows users to toggle between different states, changing the class on the UI and updating the corresponding database value. I am exploring the best practices for handling these updates efficiently.

The current approach involves:

  1. Loading the initial list when the page loads
  2. User clicks on the favorite button for an item
  3. UI JavaScript sends an update request to the database to modify the "favorite" value for that specific item
  4. Upon successful update, the backend responds with a 200 status code
  5. Frontend then fetches the updated data from the database using axios to refresh the UI list

Question: Is this the most effective way to update the UI? One concern is the delay in response time as it involves updating and querying the database simultaneously while the user makes changes.

Exploring Alternatives

An alternative approach could be to update the UI list in real-time while sending the update request to the backend concurrently. In this case, there would be no need to re-query the database since the UI data should already reflect the changes made.

Answer №1

In my opinion, the best approach depends on individual preferences. Personally, I believe that querying for specific changes is more efficient than refreshing the entire list. For example, we can request information for a specific object rather than pulling all data from the database. Alternatively, our API could be set up to return the updated object directly after a successful edit, which I find to be the most convenient method.

Some might argue that refreshing the whole list is not ideal due to various reasons:

  • Increases load on the database
  • Requires more backend processing to convert items to JSON
  • Results in higher data transfer over the network
  • Adds complexity to parsing JSON on the frontend

This approach can become burdensome, particularly with a large user base who may constantly query the database for updates they can already somewhat anticipate. If the API cannot provide instant feedback, then it's recommended to only request information for the specific changes or even skip querying altogether if we are confident in the requested changes and their successful implementation by the backend. This way, unnecessary queries and potentially overwhelming the system can be avoided.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Out of nowhere, an error emerged stating, "I am unable to access the 'name' property of undefined."

I am currently working on coding a Discord bot in JavaScript for a school project. However, I encountered an error while running my code that I can't seem to understand. This error never occurred before, and I suspect it might be due to a recent chang ...

The alert feature does not seem to be functioning properly when displaying error messages

// Issue: Alert is not working on error message. I intend to only display up to four issues, after that it should not work. success: function(msg, String, jqXHR) { window.location = 'home.html'; $("#result").html(msg, String, jqX ...

Issues with AngularJS checkbox filters functionality not performing as expected

I am tasked with implementing a filter feature using checkboxes for certain properties. Here is the code I have written: JavaScript code: app.controller("filterCtrl", function ($scope, $http) { $http({ method: 'GET', url: contextPath + ...

The error message "[Insecure URL]" was triggered at line 85 of angular.min.js in the AngularJS framework

Looking for some assistance with Angular as I have limited knowledge. It was working fine on localhost, but after upgrading from PHP5 to PHP7, I encountered this error: angular.min.js:85 Error: [$sce:insecurl] http://errors.angularjs.org/1.2.13/$sce/inse ...

The NodeJS req.query is providing inaccurate information

When I send a JSON from the Client-Side to a NodeJS Server, it looks like this: $.ajax({ type: "POST", dataType: "jsonp", url: "www.xyz.com/save", data: { designation: "Software Developer", skills: [ "", "ASP.NET", "P ...

What is the process for utilizing GruntFile.coffee and package.json to extract or create the Lungo.js example files?

I want to experiment with the Lungo.js examples found here: https://github.com/tapquo/Lungo.js. However, when I try to run the index.html in the example directory, it seems like the components and package directories are empty. Although these directories d ...

Insert information into an element of an array. Utilize React Native JSX

While attempting to compare, locate, and insert data into an array, I encountered the following error: Error => TypeError: undefined is not an object (evaluating 'data[index].push') The JSON/Array in question looks like this: [ { "ca ...

Tips for troubleshooting my website?

After making some updates to my website, I noticed that an ajax script is no longer functioning properly. Since I hired someone else to write the code, I'm not sure how to troubleshoot it. Initially, this is what it should look like: When you select ...

What is the best method for extracting the innerHTML value of html tags using a css selector or xpath?

I am currently struggling with retrieving the HTML inner text value using CSS selector or XPath. While I can achieve this using document.getElementById, I am unable to do so using selectors. I can only print the tag element but not the text from it. For e ...

Tips for saving information in an array with Vue.js?

I am working on a task where I need to fetch data from an API and store only the values that are marked as "true" in a variable. The API response is listed below: API Output Data { "BNG-JAY-137-003": false, "BNG-JAY-137-004": true, ...

What steps can I take to fix the 422 error when making a POST request?

Currently, I am working on a project following a tutorial on Udemy but creating my version. Although I have successfully implemented bcrypt and jwt for user authentication, I am facing issues when trying to make posts in my application. Whenever I attempt ...

Several middlewares using router.params()

Is it possible to include multiple middlewares as parameters in the function router.params() in Node-Express? I currently have the following setup: const checkAuth = (req, res, next) => {console.log("checking auth"); next()} const checkAuth = ...

Troubleshooting jQuery AJAX Errors in Internet Explorer 8

I've created a rather simple ajax call using jQuery. It's functioning flawlessly in IE9, the latest Firefox, and the latest Chrome, which leads me to believe that the page being posted to is working fine. However, it fails in IE8 (I haven't ...

Exploring a utility function for saving object information in a dynamic state

Imagine my state was structured like this: state = { customer: { name: { elementType: "input", elementConfig: { type: "text", placeholder: "Your Name" }, value: "" }, street: { e ...

Transferring data from a PhoneGap application to an XLS file and attaching it to an email for easy sharing

Is there any example available that demonstrates how to achieve the following functionality in Phonegap? My app retrieves data through AJAX from our server. I would like users to be able to export these results to an Excel spreadsheet which can then be at ...

Guidelines for iterating through a nested JSON array and extracting a search query in Angular

I'm currently working with a complex nested JSON Array and I need to filter it (based on the name property) according to what the user enters in an input tag, displaying the results as an autocomplete. I've started developing a basic version of t ...

The Django REST framework is sending the 'u prefix to Angular when retrieving data from the database

I'm currently using Django Rest Framework along with AngularJS to develop a website that collects information for hair stylists and stores it in a database. On another page, this information is retrieved from the database and displayed on a profile pa ...

Organizing Angular Material Styles using Namespacing

In an attempt to develop reusable components with Angular 1.4.3 and Angular-Material 1.0.5, the goal is to seamlessly integrate these components across various applications. However, a challenge arises as the Angular Material CSS contains styling rules th ...

Tips for adding list items programmatically in JQuery without generating a new HTML element

I have a list of items that I want to dynamically load more of from my database using JQuery. My current code looks like this: $("#somediv").append($("<div>").load("ajax.php?action=getresults", function() { $('#busy').delay(1500).fadeO ...

Refreshing divs each time a new record is added to the MySQL database

I am currently developing a SCADA system on my website and looking to update specific divs with GIFs only when there is a change in any of the two tables in my MySQL database. I want this update to occur every time a new record is added to one of the tabl ...