Almost all social giants have a transition to another page without reloading. To do this, they make a request, in response to which comes the page template and data. However, when only a user opens a page, they return an already assembled page from a template, while also returning its template and data. Do they duplicate the code of the page given by the server and the templates that are given to javascript? Or is there any template engine capable of generating templates for both javascript and server side? If anyone knows such libraries for python share.
- oneIs github related to such resources? When you start to view the sorts, the path changes in the address bar, and only the code on the page reloads - Anton Feoktistov
- oneHere is an example of using templates on jQuery . Here are examples for jQuery Mobile . Do not pay attention to Mobile - no one bothers you to use it on the desktop. We seem to be using this approach. - BOPOH
2 answers
The question is pretty extensive.
Of course, duplicating the page code is inefficient in terms of project support costs. In general, always try to avoid any duplication of code and content.
In the simplest case, updating the entire page is not necessary at all. The server requests only raw information in the form of JSON / XML, and the corresponding attribute or content values ​​are replaced on the current page.
In the case when you need to replace most of the content (switching to another page without reloading, for example), try to reuse the templates. Templates are either requested once during the first use, or they are already embedded in JavaScript and loaded with the page.
I can suggest you look at the mustache template engine . It has implementations for most of the languages ​​used, including Python, JavaScript, and CoffeeScript. For a more in-depth study of the topic, I suggest to start here these are Interactive sites . In particular, here it is - Reuse patterns .
- The problem remains in the template engine. How do you google such template engines like mustache? I would like to inherit patterns - zixvel47
- I cannot answer the first question - I simply know about some: from articles, RSS, etc. Concerning inheritance - mustache is able to partials (inclusion of one in another). - eigenein
There are some frameworks / libraries for creating universal (isomorphic) applications, where both client and server can "render". For example, Redux .
Google aside "Isomorphic Application with React and Redux"