Hello guys I need help from Pros about frontend and backend.
I’m ussually writing my codes into frontend I also use backend but as I learn Velo and JS functionality. I’m thinking about did I wrote backend codes to the frontend.
My question is when I should write my code to frontend and when I should write my code to backend which things I should be checking and things I should be in the knowledge.
You can also share a tutorial about this especially for Wix I want to learn about this because I’m creating almost everything with Velo and JS right now also I’m using NPM packages and Databases.
@loeix
These were just some of many use-cases. If i am honest, i also do not know everything about back-end-coding, but the main task of back-end-coding will be the SECURITY-REASON.
Some other tips…
-when working on back-end → you can’t use $w (as i figured out once myyself)
-when working on back-end your redering-engine → renders twice
-when working on back-end → you will have to pay-attention to → .then() and return-statements
Take a look here
They explain how and when to use .jsw(javaScriptWeb) modules.
In short:
The main reason is to avoid hackers to adjust the outcome from a function.
You send data to the server → The function runs on the server → the result comes back.
If you would do the same in the frontend (public files)
Then you would do the function on the users hese computer wich means they could access the data easyer to manipulate the function to get other data or more data then you would want.
Hey Exwiev, Velo-Ninja is absolutely correct. When you are retrieving data from collections, you mostly want to hide that stuff. You may also want to do some processing in the backend with some data, and then pass the finished results back to the front end. Maybe you need to read through all the records to find something, or find a group of records, you can process all the reading in the backend, then pass to the front end the results of the records you found. So if your collection has 1000’s of records, you can process them in the backend, then only return the few that meet your criteria.
Another reason is speed. Backend code runs a LOT faster than frontend code, so if you’re doing something computationally intensive, you want to do it on the backend and then send it to the frontend.
As an experiment, I wrote some code that contained very weighty database queries, ran it on both the backend and the front end, and timed it. Front end ran in about 15 seconds and backend ran in about 8.
You mean for the database calls? I’m not rendering anything…just calling a crapload of database calls. The code never runs on the front end. In my use case, I need to build a cache of frequently accessed, but rarely changing data, so I do the query once on the backend and then send the result to the front end where it is put into browser storage.