Answer the question
In order to leave comments, you need to log in
Best practices for creating one-page sites?
What is the best way to organize a site with content loading via json so that static html is available (with backward compatibility for older browsers and browsers with disabled js).
I mean MINIMIZING the creation of unnecessary logic and its duplication in the backend and front. Pulling html silently, as I understand it, is a vicious practice. The second option is to duplicate the output, but only in json, if the page comes with a def parameter.
Help me figure out how to get data from the backend in the best way. How is it accepted, taking into account possible future problems (extensibility, maintainability)?
Thank you.
Answer the question
In order to leave comments, you need to log in
Since you mentioned Rails, I will give a little help on this issue.
There is a special gem trubolinks for this. In Rails 4.0 and above, it is enabled by default. Its essence is just that turbolinks.js intercepts the click on the link, and sends a request to the address where you wanted to go in json, receives a response in json, after which it redraws the appearance of the page, and changes its address in the browser .
But this approach does not imply, in principle, one-page sites. The bottom line here is that we only load from the server what we need to display.
In general, the most general answer is simple - the server must be able to give a response to each address in the form in which it receives a request: if it was a regular GET or POST request, it returns an HTML page. A request for json came - returns json
For example, in Rails, if an html page is returned on request /users/show/1, then json will be returned at /users/show/1.json, xml - /users/show/1.xml
That is, the simplest rule looks like this any site address should be able to return both full html, partial html, and json. So that any user who opens a page can take its address, send it to another, and he would see the same (regardless of the history of his stay and actions on the site)
But I can’t understand - how does this compare with one-page sites? This is just a technique for redrawing the page image without completely reloading it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question