javascript - Best practise to give JS its initial dataset on page load -


Imagine a news that shows newsfeed as soon as a user requests a page, we go to the database (or whatever) and The Get News Feed page has already been loaded, we have dynamically added new news items (via AJAX / JSN) that means we have two mechanisms to effectively create a newsfeed. With our server-side language for initial page request, and one for javascript for any new item.

It is difficult to maintain (because when some changes happen, we have to change the JS system and server side system)

What is a good solution for this? And why? I have come up with the following conditions:

  • Javascript set an interdisciplinary set, somewhere in html, and let it create initial view when the document is ready;
  • To make JavaScript an AJAX request on the document to get initial data; Or
  • To keep it as mentioned above, the JS version and an SS version

    I bend towards the scenario first, and for that I have a follow up question: How do you give datasets to JS? In a hidden divis or something?

    Requesting another AJAX request to get data is not really expensive and you have a simple architecture . This is a big advantage.

    But another benefit you forget, by always serving the same stable resources, you have to cache them

    It seems that there is no benefit in integrating data into your initial page, only use one scheme, AJAX, and make an initial request.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -