If I need to retrieve different data independently, which one will be faster:
OPTION 1:
//front end:
Promise.all([query1, query2, query3]).then(res => {/*code*/})
or OPTION2:
//front end:
import {retrieveData} from 'backend/queries.jsw';
retrieveData([query1, query2, query3]).then(res => {/*code*/});
//backend:
export function retrieveData(queries){
return Promise.all(queries);
}
What do you think?
Do you realize that difficult questions like this give me a headache? Do you care? I thought we were friends.
I suspect that performing all of the queries in the backend will be faster. Frontend queries have a built-in mechanism which sort of automagically turns them into calls to backend functions. By doing all three in the backend, you save yourself the overhead of the frontend to backend mechanism.
If I'm optimizing a site, I generally rely on backend queries as it's a more direct interface. For just one query it might not matter, but for multiple queries backend should be more efficient.
BTW - backend queries have a big advantage in that they're more secure. Sensitive data that's part of the query is hidden from site visitors. In a backend function. you can return only the data that's meant to be viewed by your site visitors.
And of course, you can always contact the Wix support team who might be able to get a more accurate answer from some smart Wix devs, who will tell you that I'm delusional.