N
N
NewTypes2015-02-17 21:02:23
JavaScript
NewTypes, 2015-02-17 21:02:23

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

3 answer(s)
V
Vladislav Shchekoldin, 2015-02-17
@NewTypes

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.

F
FanatPHP, 2015-02-17
@FanatPHP

It's best not to make one-page sites

S
Sergey, 2015-02-17
@gangstarcj

Do not focus on users without JS, they are the last century.
What do you want to pull? Will your content change dynamically?
If there is no dynamics, do it in HTML

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question