G
G
GM2mars2015-01-23 22:11:46
PHP
GM2mars, 2015-01-23 22:11:46

What is the best way for the backend to pass the initial site data to the frontend?

For example, when opening a site, we need to transfer two data arrays: user data and menu data.
There was an option after opening the site, immediately send javascript'om an ajax request and receive a json array. Or "sew" all the necessary data into HTML (which gives the backend) and parse it with javascript'om to create a data model.
Tell me in what way is it correct / more convenient to transfer the initial data for compiling a model on the client?
Bottom line: as IceJOKER advised , I sew the data into javascript via php on the first load. I created a separate class that collects the necessary data for the client and writes it to a json string.
Thanks to all.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
IceJOKER, 2015-01-23
@GM2mars

Is it possible to immediately embed json using php and assign it to a variable?
something like:
?
You can do it this way and that, depending on how you feel more comfortable.
The request, of course, has a minus - you have to wait for an answer

Y
Yuri Shikanov, 2015-01-24
@dizballanze

You can insert the necessary data into the custom meta tag and read it into JS.

Z
Zveroboy8, 2015-01-24
@Zveroboy8

If getting data on the backend takes a little time, then immediately rake it out and insert it where necessary in html. If the page in the first option is clearly visible that it "slows down", then calculate the most resource-intensive selections and yes, load them using ajax after the page has loaded

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question