E
E
Elon2021-01-22 19:29:41
JavaScript
Elon, 2021-01-22 19:29:41

What is a local server for?

Hello, I just recently started learning programming and I have a question. How to make sure that the site does not lose all the values ​​​​when the page is updated. For example: with the help of an input, text was entered into some span on the site, and it is displayed on the page. But when you update it all disappears. As I understand it, I need some kind of local server, so that all this data would be stored there and displayed on the site. Sorry for my explanation, I don't really understand this topic. I say right away that I need it just for myself and a couple of other users, and for free.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Mors Clamor, 2021-01-22
@huziuk

All data is processed and stored by the browser, use localStorage, Google to help

A
Alexander, 2021-01-22
@Aleksandr-JS-Developer

Question:

But when you update it all disappears. As I understand it, I need some kind of local server, so that all this data would be stored there and displayed on the site

Answer:
When you open your page in a browser, the browser downloads the page and, among other things, renders the DOM (HTML markup) and your JavaScript code.
Now think, when you reload the page, the same action is triggered, the page came from the server (or from any other storage) and was rendered. How does she know what data was entered before uploading?
server side rendering

Есть технологии, позволяющие присылать страницу уже с данными, но про них речь не идёт

Therefore, in order to save data, it is necessary that at the stage of executing your JavaScript code, JavaScript requests data from the server or from localStorage .
Question:
What is a local server for?

Answer:
A local server (in web development) is often needed to simulate sending / requesting data to the server and makes it easier to configure responses to requests from the server. This allows you not to use a real server (do not forget that a real server requires money), and sometimes it’s not so smooth with uploading code to a real one. And if you make changes every couple of minutes for 10 hours in a row and want to see the result? There are all sorts of tensions.
In short, a local server is faster, cheaper, simpler, easier.
Links:
localstorage (ru)
Storing data in the browser (ru)
Deeper:
fetch (ru)
Resource, which has links to a fake rest api server. The bottom line is that you can send requests there and the real server will respond, and you will process the server response on the JS side.

D
Developer, 2021-01-22
@samodum

You can write to cookies, local storage.
No local server needed

S
Sergei Sakharov, 2021-01-24
@Afranius

I don't know myself. I use nginx + php-fpm + MariaDB
I develop in Eclipse PHP Developer
To write data to the database I use a php script
I usually use it to request and output a response in JSON format
Yes, instead of PHP you can use Node.JS
Of course, you can store data first locally, but I'm too lazy to rewrite the logic later.
(I did not understand one of the answers that "a real server requires money" - nginx works under Windows, php and MariaDB too)
600dc2390343a663009007.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question