📜 ⬆️ ⬇️

In 5 minutes, make Single Page Application available for Google and Facebook.

Introduction


Dynamic web applications (SPA, Single Page Applications) are becoming increasingly popular. Their use allows you to simplify and speed up development and support due to the following advantages:



Of the popular libraries for the SPA I want to separately highlight ReactJS. Its use allows you to create complex web applications quickly and easily, to maintain the speed of development on a large base of code, to avoid regression errors when adding new functions.


The big unsolved problem of the SPA is their complete incompatibility with web crawlers of search engines (indexing sites) and social networks (sharing in social networks). Currently, crawlers do not perform javascript on their side and therefore cannot receive the contents of the SPA as html code. In 2015, Google officially refused to support the execution of javascript code on its side.



Solutions


Today there are several types of solutions for projects that want to fully develop a SPA.


Support for custom server-side rendering


What it is


This is an old approach to the organization of a web application in which the server-side rendering of html pages is preserved. When the SPA is loaded in the client’s browser, usually the application first deletes all the html code created by the server, and its place is filled with the result of the program. Currently it is the most commonly used solution.


What's good



Why is it bad



Isomorphic rendering


What it is


The idea that the same code can be executed on both the client and the server. Unfortunately, this idea works only on very simple applications. In addition, it is very difficult to support all new browsing functions on the server, which leads to the need to often do additional work to adapt the application to work on the server.


What's good



Why is it bad



Prerender.io


What it is


This is an open source service that allows you to organize the redirection of traffic from crawlers to a special browser that executes javascript code and returns a static html page. PhantomJS is used as a browser.


What's good



Why is it bad



Integration Ways


Offers many of the same type of integration for different frameworks and web servers. They consist in proxying traffic from a crawler to prerender.io (if UserAgent matches the crawler in the request header or _escaped_fragment_ is in the request parameters). The rest of the traffic is given in the normal mode (static set).


Renderjs.io


What it is


Cloud based service, which works similarly to prerender.io, but works fast, does not use cache, uses the latest version of Chromium.


How it works


After the first download, SPA applications in modern browsers work very quickly. To draw a new page usually requires only a few requests. Renderjs.io is a service that does this for browsers. Chromium browser is used for rendering. When a crawler is first accessed in the present, the real Chromium opens a bookmark with a web application. This tab does not close for a long time. When accessing a new url, it does not completely load everything, but only pushState into an already loaded application. Thus, rendering works very quickly and is very easy to debug, if your Chromium works, it also works on Renderjs.io .


What's good



Why is it bad



Integration Ways


Integration using middleware is similar to prerender.io.


Integration with DNS records. With this integration method, the project redirects all of its traffic to cdn.renderjs.io and receives full processing of traffic from the crawler through the render service, and the rest of the traffic to its web service. This method allows small projects in 5 minutes to make your SPA accessible to search engines and to do more important things.


Follow a few simple steps:


  1. Register;
  2. Create a new project;
  3. Fill in the fields. Domain is the domain name field (mysite.com) from which requests will come, and the origin field is the url (usually the host mysite.imtqy.com) which your application rests on;
  4. Create a CNAME record on your DNS service mysite.com -> cdn.renderjs.io;
  5. Check your application (in the curl http://mysite.com terminal curl http://mysite.com or in the browser view-source:http://mysite.com/?_escaped_fragment_= );
  6. If everything is correct, get rendered html.

FAQ


Q: And why not give all customers ready html code?
A: For several reasons:



findings


We believe that for young projects at the initial level, the use of renderjs.io and DNS integration is an ideal solution that allows you to simultaneously get all the benefits of a full-fledged SPA and focus on solving really important tasks, namely creating value for the client.


New projects with traffic can also use renderjs.io with DNS integration or nginx integration.


Let big, successful projects be independent. If there is a desire to deal with problems that have already been solved, why are they big, they themselves know what to do.


About Us


purelab.io - We are a team of professional developers. We specialize in developing high-quality and modern web applications based on ReactJS. We use functional programming. We have our own solutions for doing things right. We can help, advise, develop. Write, we will be happy.


')

Source: https://habr.com/ru/post/327612/


All Articles