Disclosure of Invention
In view of this, the present application provides a method and an apparatus for processing a web page to increase a speed of loading the web page.
Specifically, the method is realized through the following technical scheme:
in a first aspect, a method for processing a web page is provided, where the method is performed by an interceptor and includes:
receiving a resource request sent to a server by a webpage client, and forwarding the resource request to the server; or receiving the resource fed back to the webpage client by the server, and forwarding the resource to the webpage client;
obtaining network state information according to the resource request and the resource;
and sending the network state information to the webpage client so that the webpage client sets a webpage loading strategy according to the network state information.
In a second aspect, a method for processing a web page is provided, where the method is performed by a web page client, and includes:
receiving network state information sent by an interceptor, wherein the network state information is obtained by the interceptor according to a resource request sent by a webpage client to a server and a resource fed back by the server to the webpage client;
and setting a webpage loading strategy according to the network state information.
In a third aspect, a web page processing apparatus is provided, including:
the forwarding module is used for receiving a resource request sent to a server by a webpage client and forwarding the resource request to the server; or receiving the resource fed back to the webpage client by the server, and forwarding the resource to the webpage client;
the statistical module is used for obtaining network state information according to the resource request and the resource;
and the pushing module is used for sending the network state information to the webpage client so that the webpage client sets a webpage loading strategy according to the network state information.
In a fourth aspect, a web page processing apparatus is provided, including:
the system comprises an information receiving module, a network state information processing module and a network state information processing module, wherein the information receiving module is used for receiving the network state information sent by an interceptor, and the network state information is obtained by the interceptor according to a resource request sent by a webpage client to a server and a resource fed back by the server to the webpage client;
and the webpage loading module is used for setting a webpage loading strategy according to the network state information.
According to the webpage processing method and device, the network state information is obtained according to the resource request and the resource, and the network state information is sent to the webpage client, so that the client sets a webpage loading strategy according to the network state information, the webpage loading can accord with the real network state, the webpage loading method and device adapt to the change of the network state, and the webpage loading speed is improved.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
People often browse web pages on terminals, for example, a Taobao page can be opened on a smartphone (or PC) through a browser, or a page of a certain social network site can be opened through the browser. Referring to fig. 1, a user opens a plurality of clients through a browser 11, which may include a panning client, a news client, a social networking site client, and the like, for example, and each client is a web page opened in the browser 11, which may also be referred to as a "web page client" in the embodiments of the present application.
As shown in fig. 1, each web page client corresponds to at least one server, for example, a web page displayed by a panning client (the client is an application client provided by a panning company to a user and can provide services such as shopping) may be sent by the server 13 to a browser for parsing and displaying, a web page displayed by a social network client (the client is an application client provided by a social company to a user and can provide services such as social interaction) may be sent by the server 14 to a browser, and a web page displayed by a news client (the client is an application client provided by a news company to a user and can provide services such as news) may be sent by the server 15 to a browser for displaying. Because the web page of the client is analyzed and displayed in the browser, data interaction between the client and the server is performed through the browser, for example, a resource request for requesting resources (the resources include, for example, pictures, texts, videos, and the like in the web page) sent from the client to the server is sent by the browser, and resources fed back to the client by the server are also received by the browser.
In conjunction with fig. 1 and fig. 2, assuming that a data interaction channel between the browser and the server is referred to as a network channel, the channel may include a network outlet and an external network. The network outlet may have a convergence function, all requests sent by the client to the server pass through the location of the network outlet, and all data fed back by the server to the client also passes through the network outlet. In the embodiment of the present application, an "interceptor" 12 is provided at the network egress location. For example, the interceptor 12 may be part of a browser, or may be a functional module of a terminal (e.g., a mobile phone, a PC, etc.) as shown in fig. 1, which is independent of the browser.
Fig. 3 illustrates a processing flow executed by the interceptor, and it should be noted that the following sequence numbers of processing steps such as 301 and 302 do not limit the execution order among the steps, for example, 302 and 301 may be executed in parallel. As shown in fig. 3, the method may include:
in step 301, the interceptor may perform forwarding functions including: receiving a resource request sent to a server by a webpage client, and forwarding the resource request to the server; or receiving the resource fed back to the webpage client by the server side, and forwarding the resource to the webpage client. The normal operation of network communication is ensured through the request or data forwarding of the step.
The interceptor is arranged at the position of the network exit layer, so that the resource requests sent to the server by each webpage client pass through the interceptor; and the resources returned by the server side to the webpage client side are also forwarded to the webpage client side by the interceptor.
Meanwhile, in the process of performing data forwarding by the interceptor, the interceptor can also count the network state information of the network channel where the interceptor is located. As shown in fig. 2, the interceptor itself is located on a network channel between the client and the server, and it can count the network status information of the network channel. For example, in step 302, the interceptor may statistically obtain network status information according to the received resource request and the resource. The network status information includes, but is not limited to: network speed statistical information and various data flows.
In step 303, the interceptor may send the network status information to the web client, so that the web client may set a web loading policy according to the network status information. Fig. 4 shows the role of the interceptor, and the interceptor is not only responsible for normal data forwarding, but also actively pushes network state information to the web client, so that the web client adjusts the web loading policy accordingly.
The network state information is one of the important factors affecting the loading effect of the web page, for example, if the network speed is low, the web page may be loaded slowly, and at this time, if the client adjusts the loading policy, the client instructs the server to send a low-quality picture, or delays to load part of the resources, the network congestion may be reduced to a certain extent, and the display speed of the web page is increased. Therefore, in this embodiment, the interceptor is configured to obtain the real-time current network state and provide the current network state to the client as a basis for adjusting the webpage loading policy.
In a traditional mode, a webpage client usually cannot acquire an accurate and reliable real-time network state, so that the client cannot set an accurate and reasonable webpage loading strategy, and the webpage loading effect is possibly poor; in the embodiment of the application, the interceptor is arranged to acquire the network state information and provide the network state information to the webpage client, the network state acquired by the interceptor is accurate and reliable due to the fact that the interceptor is arranged at the network outlet on the network channel, and the client can also reasonably adjust the webpage loading strategy according to the network state information by providing the network state information to the webpage client, so that a better webpage display effect is achieved.
For example, in step 303, the interceptor may send the network state information obtained by statistics to each web client in a web socket manner, for example, in the scenario shown in fig. 1, the interceptor may send the network state information to a panning client, a social networking site client, a newcomer client, and the like. The interceptor can be connected with each webpage client through a web socket interface, and the information is transmitted in the web socket mode, so that the transmission cost is low, and the influence on the normal business process cannot be caused. And the interceptor can count the network state information in real time and push the network state information to the client in real time. For example, assuming the interceptor is to count the total network traffic every 10 seconds, the network status information may be sent to the web client every 10 seconds.
Two types of statistical processing of network state information performed by the interceptor side are listed as follows:
in one example, the interceptor may count the number of requests for the resource request currently in progress, as well as the total network traffic per unit time. For example, for a client-side web page opened through a browser, multiple resource requests may be generated, and different requests may be used to respectively request different types of data in the web page, such as a request for web page text from a content server or a request for pictures in the web page from a picture server. Since all requests pass through the interceptor, the interceptor can count the current number of requests, which may be the requests the interceptor is in progress at the time of pushing the network state information to the web client.
In addition, the total network traffic per unit time includes the total data traffic of each client. For example, suppose a browser is opened on a terminal, a plurality of web page clients are operated on the browser, and the sum of the traffic between the web page clients and the respective server is the total network traffic; the total network traffic per unit time is, for example, the total traffic in 10 seconds, that is, the total network data transmission amount in 10 seconds is counted by the interceptor every 10 seconds. For another example, if multiple web page clients are running on the terminal through multiple browsers, the total network traffic is also the sum of the traffic of the clients including the respective browsers.
In another example, the interceptor may obtain the number of different types of requests in the resource request, which are sent to different servers, respectively. For example, the interceptor receives 10 resource requests, 8 of which are used to request some picture resources from the surf server, and 2 of which are used to request picture resources from the panning server. That is, the interceptor can perform a detailed analysis of various types of traffic in the network channel, which all help the web client support the adjustment of the web loading policy, which can be referred to in the description of the method at the client side.
The web page client can receive the network state information sent by the interceptor and determine how to load the web page resource according to the network state information. The process executed by the client may refer to fig. 5, which includes:
in step 501, network state information sent by an interceptor is received, where the network state information is obtained by the interceptor according to a resource request sent by a web client to a server and a resource fed back by the server to the web client. For example, the interceptor may push network status information to the client every 10 seconds, so that the client knows the current network condition in real time.
In step 502, the web client may set a web loading policy according to the network status information.
The following two examples, corresponding to the above two examples of statistical processing of network state information by the interceptor, describe how the web client adjusts the web loading policy after receiving the information:
in one example, the network state information sent by the interceptor to the web client includes: the client can determine the network speed state of the current network according to the request quantity of the resource requests and the total network flow in unit time. For example, if an index threshold is set, the request quantity threshold is set to be 8, the unit time is 10 seconds, the total flow threshold in the unit time is 0.8M, and if the index threshold is set to exceed the threshold, it indicates that the current network is congested and the network speed is low. Then, when the number of requests of the current resource request is 10 and the total network traffic in 10 seconds is 1M in the network status information fed back by the interceptor, the client may determine that the network speed is low at this time. Optionally, the threshold storage and the network speed determination may be performed on the client side, or may be performed on the interceptor, and the interceptor directly notifies the web page client of the determination result of the low network speed.
When the web page client determines that the network speed is low, the client can adjust the sending frequency of the resource request or the attribute information of the requested resource.
For example, an example of adjusting the transmission frequency of the resource request is as follows: assuming that 100 pictures are loaded in a webpage, 10 pictures are loaded when the webpage is opened, then the client receives the network state information sent by the interceptor, the number of requests of the current resource request is 10, the total network flow within 10 seconds is 1M, and the client can temporarily stop loading the subsequent pictures if the client determines that network congestion may occur at this time through analysis and the network speed is low. After 10 seconds, only 2 network requests are left to be in progress according to the network state information sent again by the interceptor, and the network traffic is also lower than 1M, the client can continue to load the next 10 pictures. The strategy is a strategy for delaying the loading of part of resources at low network speed, can reduce the network load, prevent the network from serious congestion, and improve the network recovery efficiency and the webpage display speed.
For another example, an example of adjusting the attribute information of the requested resource is as follows: when a web page client sends a resource request to a server and requests to transmit picture resources required by web page display, it is assumed that network state information received by the client and transmitted by the server includes: the request quantity of the current resource request is 10, the total network flow in 10 seconds is 1M, the analysis determines that network congestion may occur at this time, and the network speed is low, so that the client can instruct the server to send a low-quality picture at this time, so as to reduce the transmission quantity of network data. This is an example of adjusting web page information according to the network speed, the server may store multiple versions of pictures, such as a high-quality large-size picture and a low-quality small-size picture, and the client may instruct the server to dynamically adjust the attribute information (e.g., size) of the sent picture according to the network speed.
In another example, the network state information sent by the interceptor to the web client includes: when the number of the resource requests of different types is large, the client can adjust the loading sequence of the resources corresponding to the resource requests of different types. Examples are as follows: assuming that the interceptor obtains the current ten network data requests statistically, eight of the requests are requests for resources from the surf server, and the other two requests are requests for resources from the pan server, that is, the current communication link with the surf server is relatively heavy, the web client may load the resources of the pan server after acquiring the information, because the communication link with the pan server is light in load and the loading speed is faster.
As seen from the execution flow of the client shown in fig. 5, the web client can obtain the current network state in real time with the assistance of the interceptor pushing the network state information, and the network state information fed back by the interceptor is accurate and reliable, and the client can obtain the accurate and reliable network state information to know the use condition of the current network more clearly, so as to adjust the loading policy of the web page more reasonably and make the loading effect of the web page of the client better (e.g., smoother and faster).
In order to implement the above-mentioned web page processing method, in the embodiment of the present application, a functional module, such as an interceptor, for implementing the method may be implemented in a software form, for example, may be implemented by Javascript. The embodiment of the present application may refer to a functional module for implementing the above method as a web page processing apparatus. As shown in fig. 6, the web page processing apparatus may be an application interceptor, including: a forwarding module 61, a statistics module 62 and a push module 63.
The forwarding module 61 is configured to receive a resource request sent by a web page client to a server, and forward the resource request to the server; or receiving the resource fed back to the webpage client by the server, and forwarding the resource to the webpage client;
a statistic module 62, configured to obtain network state information according to the resource request and the resource;
the pushing module 63 is configured to send the network state information to the web client, so that the web client sets a web loading policy according to the network state information.
Further, the pushing module 63 is configured to send the network state information to the web page client according to a predetermined time interval.
Referring to fig. 7, based on the structure shown in fig. 6, the statistical module 62 may include:
the network speed determining submodule 621 is configured to obtain the number of requests of the resource request currently in progress and the total network traffic in unit time;
and the network subdivision sub-module 622 is configured to obtain the number of different types of requests in the resource request, where the different types of requests are sent to different servers respectively.
Fig. 8 illustrates a web page processing apparatus, which may be applied to a web page client, and as shown in fig. 8, the apparatus may include: an information receiving module 81 and a web page loading module 82.
The information receiving module 81 is configured to receive network state information sent by an interceptor, where the network state information is obtained by the interceptor according to a resource request sent by a web client to a server and a resource fed back by the server to the web client;
and the webpage loading module 82 is used for setting a webpage loading strategy according to the network state information.
Further, the web page loading module 82 is configured to adjust a loading sequence of resources corresponding to different types of resource requests according to the number of the different types of resource requests included in the network state information.
Referring to fig. 9, the web page loading module 82 in the apparatus may include:
the information analysis submodule 821 is configured to determine a network speed state of the current network according to the request quantity of the resource request included in the network state information and the total network traffic in unit time;
and the policy setting submodule 822 is configured to adjust the sending frequency of the resource request or the attribute information of the requested resource according to the network speed state.
By arranging the web page processing device shown in fig. 8 or 9 at the web page client, the web page client can receive the network state information sent by the interceptor, and adjust the loading strategy of the web page according to the network state information, thereby accelerating the display speed of the web page.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.