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.
Today there are several types of solutions for projects that want to fully develop a SPA.
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.
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.
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.
<meta name="prerender-status-code" content="404">
( https://prerender.io/documentation/best-practices );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).
Cloud based service, which works similarly to prerender.io, but works fast, does not use cache, uses the latest version of Chromium.
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 .
<meta name="status-code" content="404">
;history.pushState
used to change the url, then going beyond the boundaries of the application will not work.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:
curl http://mysite.com
terminal curl http://mysite.com
or in the browser view-source:http://mysite.com/?_escaped_fragment_=
);Q: And why not give all customers ready html code?
A: For several reasons:
rendering takes time - it's still longer than getting a set of static (html, js, css) from cdn.
Q: How to index closed sections that require cookies?
A: Technically, this is possible, but not required in practice.
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.
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