How to optimize dynamic calculator performance using JavaScript and lightweight backend APIs? [closed]

I’m developing a small web-based calculator tool (a financial or estimation calculator) that performs real-time calculations using JavaScript on the frontend. However, as the logic has grown, I’ve started offloading some operations to a lightweight backend API (Node.js + Express).

The challenge I’m facing:

  • Sometimes, calculations lag when multiple users hit the tool simultaneously.

  • API responses are fast locally but become slower when deployed online.

  • I’ve tried implementing local caching using localStorage on the frontend and simple in-memory caching with Node.js on the backend, but I’m not sure if this is the best approach.

  • I also tested asynchronous calculation batching using Promises to reduce response time, but it didn’t help much under concurrent load.

I’d love some advice on:

  1. What’s the most efficient way to handle repeated calculations — browser-side caching, service workers, or something like Redis?

  2. Should I shift more logic back to the frontend and reduce server hits?

  3. Any best practices for keeping such tools lightweight while maintaining accuracy and responsiveness?

I was expecting smoother performance and faster responses when multiple users accessed the calculator at the same time, but the lag still appears randomly — especially when API calls stack up.

Czech cadastre API

I need use API of Czech Cadastre, but in console I see Error.

This is my code in javascript:

const url = 'https://api-kn.cuzk.gov.cz/api/v1/Parcely/Vyhledani'
const api_key=''

async function getData() {
    const response = await fetch(url)
    const data = await response.json()
    console.log(data)
}

getData()

From console:

script.js:5 
 GET https://api-kn.cuzk.gov.cz/api/v1/Parcely/Vyhledani 401 (Unauthorized)
getData @   script.js:5
(anonymní)  @   script.js:10

JavaScript library not working correctly when not added as script on page that it is being used on

I want to use an implementation of Ion JavaScript library in my Java application with a JSP frontend.

If I add:

<script type="text/javascript" src='<c:url value="https://path/to/library/assets/ion/v6/stable/extensions/require/loader.js"/>?_=<c:url value="${cacheBuster}"/>'></script>

to the JSP page I’m looking to use it on, the below feature works correctly and I can see the library in the page sources in my Developer Tools.

<div class="m-card m-card-notification m-card-notification--warn" role="status" data-module="m-card-close" data-notification-description="close icon">
    <div class="m-card-content">
        <div class="m-card-content__inner">
            <p>Some text here.</p>
        </div>
    </div>
</div>

Long term, however, I may wish to use this library in different parts of the UI, so I’d like to place this in a more suitable location. Again, when I load the page, can see the library in the page sources in my Developer Tools but the ‘X’ icon that should appear and hide the div if clicked does not load. It should appear with the addition of data-module="m-card-close" Do I need to include the <script> above in every page I want to use some feature from this library or is there a cleaner way to do this?

PhpWord and n in line together with HTML code

Using PhpWord in my PHP project gives me issues.
I do have a variable containing CR/LF (n) and HTML code.
Something like:

$str='<div style="font-style: italic; text-align:center">Line1
line2
line3</div>';

The text is comming out of a MySql text field containing n as line separator.

When processing this text with PhpOfficePhpWordSharedHtml::addHtml, I am losing the CR/LF. All text is concatenated. When replacing n with html CRLF
$str=str_replace("n","<br>",$str); and then use addHtml, it gives me run-time errors:

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: br line 1 and div in Entity, line: 1 in /customers/7/4/3/ofiser.be/httpd.www/vieringen/vendor/phpoffice/phpword/src/PhpWord/Shared/Html.php on line 94

How can I process this text? Any help is appreciated.

how to fetch data from database with php (custom tables) and insert them into wordpress elementor element loop [closed]

I’m learning WordPress and migrating a site I built using plain HTML, CSS, jQuery, and PHP over to it. I’ve found that, using shortcodes, I can pull values from the database and display them on the frontend.

I’m using the free version of Elementor.

What I want to know is: can I fetch data directly from PHP and build the layout with iteration using Elementor, on top of that data? Obviously, I don’t know how many records I’ll be retrieving (it could be 5, 7, or 1,000 from the database). In other words, I’d like to pull a styled container and somehow inject each data item into it (each one inside a styled container), without having to worry about how many items are coming.

From what I’ve seen on ChatGPT, Google, etc., the typical suggestions are:

use the paid version of Elementor with something called Custom Fields (ACF), which I don’t want to pay for,

manually build everything with PHP using loops and string concatenation, which I’d like to avoid,

or fetch everything to the front and handle it with JavaScript.

Since my site will need to pull different sets of data on different pages (meaning I’ll need to iterate over that data and build layouts dynamically), if the answer is that Elementor can’t really handle this, then it seems like I would’ve been better off just skipping WordPress and doing it the traditional way.

So I’m wondering: what’s the actual advantage of using WordPress for these kinds of sites? Is it only useful when the content is fixed—static text and images?

PHP mysqli reusable functions for SELECT and INSERT/UPDATE queries [closed]

I’m learning PHP and wanted to create two simple reusable functions for MySQL database access —
one for selecting data, and one for modifying data.

I’m not sure if this is a good and safe way to handle it.
Can this structure cause any issues (for example: performance, error handling, or security problems)?

Here’s my code:

<?php
function getData($sql) {
    $db = new mysqli("localhost", "root", "", "cars");
    if ($db->connect_errno != 0) {
        return $db->connect_errno;
    }

    $result = $db->query($sql);
    if ($db->errno != 0) {
        return $db->error;
    }

    if ($result->num_rows == 0) {
        return [];
    }

    return $result->fetch_all(MYSQLI_ASSOC);
}

function setData($sql) {
    $db = new mysqli("localhost", "root", "", "cars");
    if ($db->connect_errno != 0) {
        return $db->connect_errno;
    }

    $db->query($sql);
    if ($db->errno != 0) {
        return $db->error;
    }

    return $db->affected_rows > 0 ? true : false;
}
?>

I expected these two functions to simplify my database access:

  • adatel() should return all selected rows as an array
  • adatVal() should return true/false depending on whether the query affected rows

It seems to work, but I want to make sure this is a good approach.
Should I use prepared statements instead, or is this fine for small school projects?

Laravel production error: “No application encryption key has..” and artisan key:generate fails [closed]

I deployed a Laravel 10 application (Ubuntu 22.04, Nginx, PHP 8.2-FPM). When hitting the login endpoint from my Vue frontend I got a 500 and this log entry:

production.ERROR: No application encryption key has been specified.

When I tried to run php artisan key:generate

I got instead:
In StreamHandler.php line 156:
The stream or file “/var/www/html/laravel-api/storage/logs/laravel.log” could not be opened in append mode: Failed to open stream: Permission denied
The exception occurred while attempting to log: file_put_contents(/var/www/html/laravel-api/.env): Failed to open stream: Permission denied

Environment

Laravel 10
Ubuntu 22.04
Nginx + PHP 8.2-FPM (user: www-data)
Manual deployment (no Docker)
The app had been built with php artisan config:cache earlier (before APP_KEY was properly generated) and after that all requests returned 500.

I suspect it is both a permissions issue and a cached configuration problem, but I want to confirm the correct, secure remediation steps (without using chmod 777).

What I tried:

php artisan config:clear → still the same error
chmod -R 777 storage → temporarily allows key:generate (I know this is insecure)
Re-ran php artisan key:generate but php artisan config:show app.key still empty
Cleared browser cache / restarted php-fpm (no change)
Rebuilt config cache too early (php artisan config:cache) while APP_KEY was still missing
Expected:

Laravel should have a valid APP_KEY in .env
php artisan config:show app.key should display the base64 key
No 500 error on authenticated endpoints

Trying to set HttpOnly but no changes are working

After a PenTest was told to set the HttpOnly flag on all of our cookies.

We have an Ubuntu Server 22.04 & 24.04 LAMP stack with a WordPress website. I have made changes to

  1. /etc/apache2/apache2.conf
  2. /etc/php/8.3/php.ini
  3. /var/www/html/wp-config.php

Each time, after clearing cookies in an Incognito (or InPrivate) Window and refreshing I see in the developer view in the browser the flags for HttpOnly or Secure are not checked.

what I have done

APACHE

First I make sure mod_headers is enabled by verifying headers.conf is located in /etc/apache2/mods-available/ and /etc/apache2/mods-enabled/.

In the /etc/apache2/apache2.conf file I add

<VirtualHost *:80>
Header edit Set-Cookie "(?i)^((?:(?!;\s?HttpOnly).)+)$" "$1; HttpOnly"
# or
 Header edit Set-Cookie ^(.*)$ "$1;HttpOnly"
</VirtualHost>

PHP

I add to or make sure these lines are uncommented in the /etc/php/8.3/fpm/php.ini file the following commands.

session.cookie_httponly = 1
session.cookie_secure = 1
session.use_only_cookies = 1

For good measure I set this also in the /etc/php/8.3/cli/php.ini file as well.

WP-CONFIG.PHP

The third place I’ve read to make setting changes is in the wp-config.php file found at the root of the WordPress site. So in my case, at /var/www/html/wp-config.php.

@ini_set('session.cookie_httponly', true); 
@ini_set('session.cookie_secure', true); 
@ini_set('session.use_only_cookies', true);

These lines are put in the file between these two commented lines in the file.

/* Add any custom values between this line and the "stop editing" line. */

/* That's all, stop editing! Happy publishing. */

RESTART APACHE

Then I test and restart Apache

# check the syntax
sudo apachectl -t

# restart
sudo systemctl restart apache2

# check
sudo systemctl status apache2

CHECK THE BROWSER

Then I delete the cookies, refresh the page or close the browser and re-open the site in Incognito or InPrivate mode, but the cookies never show HttpOnly or Secure being flagged.

Can a backend using Multer for file uploads recognize an image sent as a byte[] in the request?

In a B/S architecture system, the backend is written in Node.js and uses Multer to handle file uploads, and the frontend is an Android application written in Java. If the frontend gets photo data from the camera as a byte[] (YUV), transforms it to JPEG form’s byte[], wraps it to multipart/form-data, and sends it to the backend, can Multer correctly recognize this uploaded file and save the picture successfully?

The code in Android is like this:

public void login(String account,, byte[] photoYUVBytes, final LoginCallback callback) {
        RequestBody accountBody = account != null ? RequestBody.create(MediaType.parse("text/plain"), account) : null;
        MultipartBody.Part photoPart = null;
        if (photoYUVBytes != null) {
            Camera.Size size = MainFragment.getPreviewSize();
            byte[] photoBytes = yuvToJpeg(photoYUVBytes,size.width,size.height);
            RequestBody photoBody = RequestBody.create(MediaType.parse("image/*"), photoBytes);
            photoPart = MultipartBody.Part.createFormData("photo", "face.jpg", photoBody);
        }

        Call<LoginResponse> call = loginApi.login(accountBody, photoPart);
        call.enqueue(new Callback<LoginResponse>() {
            @Override
            public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
                if (response.isSuccessful() && response.body() != null) {
                    callback.onSuccess(response.body());
                } else {
                    callback.onError(...);
                }
            }
        });
    }

and the backend code is like this:

const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads/'); // store catalog
    },
    filename: function (req, file, cb) {
        const ext = path.extname(file.originalname) || '.jpg'; 
        cb(null, `${Date.now()}${ext}`);
    }
});
const upload = multer({ storage: storage });
router.post("/login", upload.single("photo") , async (req, res) => {...}

React + Vite + React Helmet: Dynamic meta tags not showing correctly when sharing on WhatsApp

I’ve built a React project using Vite, and I’m working on improving SEO and link previews.
I’m using React Helmet to dynamically update the meta title and description based on the current route. When I check in the browser, the title and meta tags update correctly in the dev tools.
However, when I share the link on WhatsApp (or any social media), the preview always shows my home page’s title and description, not the ones set for the specific route.

I’ve added all the required Open Graph tags, but it still doesn’t work.

Verified meta tags in browser (they update dynamically)

Added og:title, og:description, og:image, and og:url

Used React Helmet

Deployed the app (so it’s not a localhost issue)

I want to make casual school calendar web site [closed]

I’m making school calendar web site.
but web site design isn’t perpect in my mind.
I want to change web design.
but I don’t know how change web design.
can you advise mt web site design

this is my first web site design
but this design is dull in color
thus I want to change color of web site and ui
this is my second web site design
I changed color of web site but this isn’t perpect my mind and I don’t know changing ui

Using embedded youtube playlist index to cycle through array

I have a youtube playlist embedded in an iframe and was hoping to use the playlist index to cycle through an array of titles on-screen (i.e. when the next video starts playing, the next item in the array will show). Is this possible? What am I doing wrong? Apologies in advance because I’m very new to JS… this might be gibberish but I felt like I was on to something.

var myArray = ["song 1", "song 2"];

var player;
  function onYouTubePlayerAPIReady() {
    player = new YT.Player('video', {
        events: {
            'onReady': onPlayerReady
        }
    });
}

 function onPlayerReady(event) {
    console.log(Array.from(document.querySelectorAll('.ytd-playlist-video-list-renderer #video-title')).map((el) => {return el.textContent.trim()}).sort().join("n"))

  var Number = 
function(){
     player.getPlaylistIndex();
};
  var print = document.getElementById('print');
print.innerHTML = myArray[Number];
    }