Answer the question
In order to leave comments, you need to log in
Am I separating FrontEnd and Backend correctly?
I will try to convey the problem as accurately as possible.
So I have a website. It has a separate structure, BackEnd and FrontEnd
For FrontEnd - a separate server, for the backend - also a separate one, let's call them front.domain.com and back.domain.com. Here I will make a reservation, perhaps I do not correctly separate Front and Back, this is the first time I work with such a cross-server structure, so perhaps a mistake was made even in the "foundation" of the project.
Check if I'm doing it right?
1. On the ForntEnd server - page rendering, but not with JS, but with PHP. Why - I will specify below, maybe this is also not true
2. On the BackEnd server - getting data from the database, some functions, for example, getting the number of subscribers
3. After going to the link: for example, domain.com/catalog, the required page is loaded, all dynamic values ​​​​are inserted there using PHP, then when navigating through the pages, the site simply loads the necessary content into the block, so with all links.
Finally, the question itself.
Actually, everything would be on the 1st server, i.e. both BackEnd and FrontEnd - I could simply include the site API file require("api.php") in the catalog.php file . But I'm like that, I want ForntEnd and BackEnd on different servers. Okay, you can get out of the situation: write the entire API code in ForntEnd, but what kind of ForntEnd is it then if it pulls data from the database)) Because of this, I doubted whether I was separating these two components correctly.
I know that the front is roughly speaking what is processed on the client. I can do everything in JS, but then how do I do redirects without reloading the page? at the same time, so that there is also a dynamic link to the resource
Answer the question
In order to leave comments, you need to log in
You have a problem with definitions:
frontend - everything that works on the client side, i.e. html markup, css styles, javascript scripts.
backend - the server part responsible for receiving/processing/returning data, including generating html if necessary.
Specifically, in your case, everything that is written in php is the backend, no matter what tasks are performed in it.
As for the separation of servers, everything is simple here: on one, you implement api (read about REST right away) in which you implement data processing (models and business logic), on the second, implement routing and generate the frontend part (view), which will already work with api. But I would refuse dynamic generation in php, in favor of a static front working with api directly through js.
There is no one approach, you have specific tasks, you select a solution (architecture) for them, you can constantly prepare the frontend on the backend, you can give a pre-prepared frontend (in the form of HTML or JS files to the user) which will then collect a more complex view in your browser product.
==
You just need to decide how you would like to exchange data between the frontend and backend, usually using the JSON format (not required).
Now a scheme is often common in which - JS scripts in the client browser load only JSON with data from the backend and display this data in more complex forms directly in the browser.
P.S.
the logic of redirects and any such routing can be written on the frontend itself, intercepting user requests and processing them in a specific way, requesting the necessary data from the backend via api.
I know that the front is roughly speaking what is processed on the client. I can do everything in JS, but then how do I do redirects without reloading the page? at the same time, so that there is also a dynamic link to the resourceThis is where it was necessary to start, and this is how to end your question! Everything else is meaningless.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question