Current location - Education and Training Encyclopedia - Education and training - Beida Jade Bird Design Training: How to Optimize the Website?
Beida Jade Bird Design Training: How to Optimize the Website?
With the continuous development of the Internet, more and more consumers begin to access the network through mobile terminals and receive the information they need.

And the dissemination of this information needs to be realized through mobile web pages, so let's learn about the optimization methods of mobile web pages together.

WEB server optimization is mainly based on HTTP interface services provided by back-end services, and front-end separation is realized by using nodejs. The server optimization here mainly refers to the optimization of the WEB server implemented in nodejs.

The purpose of optimization is to improve the response and concurrency of the server and give full play to the asynchronous and non-blocking characteristics of nodejs, mainly from the following aspects.

Optimization of Interface Service Call For the route displayed on a page, to handle this route, it may be necessary to call multiple interfaces and handle interface logic.

Interface merging We merge the interfaces that can be merged when calling the page to reduce the number of interface calls. For example, taking the product details page as an example, some features of the product can be returned in one interface, so as to minimize the number of interface calls, because each interface processing has the processes of network IO, object serialization, compression and decompression.

Interfaces are called asynchronously, but not all interfaces can be merged. For interfaces that cannot be merged, we try to make use of the asynchronous non-blocking characteristics of node to make asynchronous calls, and call multiple interfaces at the same time, and the call time depends on the slower interface.

Let's be clear here: for interface dependence, such as interface A depending on the return result of interface B, in this case, we'd better sort out the interface design and reduce such serial calls, because in this way, the call time consumption is the sum of the time consumption of multiple interfaces.

Reducing the amount of data returned by interface interaction data will lead to JSON serialization, data batch object processing and additional performance loss.

You can simplify the data structure returned by the interface, return the necessary fields (the page will display the used data) and adjust the number of returned items.

So as to reduce the size of the returned message data body.

In addition, gzip compression is needed when requesting an interface, which can greatly reduce the network transmission time. Although decompression will consume some CPU time, the loss of docking network IO is still worth it.

Optimization of business processing Now our main server-side business processing mainly deals with page logic, such as routing control, session processing, view object processing, template rendering and so on.

We have made some optimizations in these processes.

Optimization of template rendering in practical use, we found that template rendering is very performance-consuming. If we deal with the preprocessing process of special templates during user access, it will be more than one order of magnitude slower, so we advance the preprocessing process (converted hbs) and precompile it when starting the web application.

At the same time, we find that some default configuration properties of the handle, such as restore processing, will lose some performance in the process of string splicing, so we can turn off the restore of html fragments.