Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:50:36+00:00 2026-05-26T05:50:36+00:00

This is a general question. Using an example below, suppose that I have a

  • 0

This is a general question. Using an example below, suppose that I have a Javascript that performs an AJAX call on a PHP script to pull data from a database. I can choose to:

a) manipulate the data on the PHP script itself before encoding an sending it back to the Javascript, OR;

<?php
 while ($row = mysqli_fetch_assoc($result))
 {
  extract($row);
  array_push($data, array('product' => $product, 'discount' => $price*0.15));
 }
 echo json_encode($data);
?>

b) get raw data from the PHP script and do the manipulation on the Javascript.

<SCRIPT type='text/javascript'>
 $.each(json, function(index, element) {
  element.discount = 0.15*element.price
 }
</SCRIPT>

Though I already know that I can get better performance (server-side) using option b), I would like to hear from the community whether it is a wiser choice and whether there are any logical arguments against it which I may have overlooked. Thanks!

NOTE:

  • This is just a simple scenario, the calculations are more complicated
    than *0.15.
  • Javascript is a must-have to pull data and for application to
    work.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:50:37+00:00Added an answer on May 26, 2026 at 5:50 am

    Some things you do not want to be stingy on when it comes to performance or time taken to execute.

    • Cryptography is one of them.
    • Anything with a financial aspect to it, is another.

    The fact that we can do XYZ on the client layer, through JavaScript doesn’t mean that we should be compelled to do it.
    What happens

    A) If JavaScript is turned off.
    B) You rely on the value POSTed from JavaScript. (Imagine a shopping cart which has $_POST[‘total_amount’] which is used by the server. I am going to edit that POST or hidden input to get free things.

    If what you are doing is purely informative, then this does not matter as much, but if you rely on any information, then you should be checking the prices multiple times.

    Additionally, what happens when you want to start providing an API or something to your service. Your transport is now broken because it doesn’t contain the calculated prices.

    DO it server side, at whichever layer better. As Duncan says, SQL could be one option, or PHP. I don’t have a preference on this one since any gains for a smallset of items will be largely negligible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a general question that just popped into my head that I have
This is a general question about character encoding when using MD5 libraries in various
this may be a more general opengl question. using OpenGL ES for 2d, and
This is a general question of sorts, but do you think that it's important
This is a general design question about how to make a web application that
This is a very general question that's not related to a specific language. I'm
I have a general question about using Servlet and JDBC. For instance, I have
This is sort of a general question that has come up in several contexts,
Yesterday I asked this general question about decimals and their internal precisions. Here is
This is a general question about MVC as a pattern, but in this case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.