Detailed Description
In order to make those skilled in the art better understand the technical solutions in one or more embodiments of the present disclosure, the technical solutions in one or more embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in one or more embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments, and not all embodiments. All other embodiments that can be derived by one of ordinary skill in the art from one or more embodiments of the disclosure without making any creative effort shall fall within the scope of protection of the disclosure.
Web pages are built in many APPs, for example, client APPs of many e-commerce platforms use the Web pages to display commodities. The Web page running in the APP can be called a mobile Web page, and the mobile Web page can be loaded and displayed through a WebView component of a mobile terminal. One type of resource that may be included in a mobile Web page is a page static resource, such as a CSS file for setting page styles, a js file for generating page interaction properties, and so on.
In a mobile Web page, the resource file of the static resource of the page may include a plurality of files, which may have different file names, for example, common. The number and the name of the resource files of the static resources included in the page can be determined according to actual business requirements, and the resource file of each page static resource can have a corresponding function in page display.
The resource file of the page static resource may also be updated, for example, sometimes the style and layout of the mobile Web page needs to be updated, or some fine adjustment is made to the interaction characteristic of the page, so that the resource file corresponding to the changed page characteristic needs to be modified at this time. For example, suppose a certain mobile Web page in a mobile terminal APP upgrades the style in the page, and correspondingly, the content in the CSS file used by the page is updated, and some codes of new styles are added.
Referring to fig. 1, fig. 1 illustrates an update structure of a static resource of a page. The resource file of the static resource may be stored in the static resource server 11. A mobile Web page 13 is loaded and displayed on the mobile terminal 12, and the resource file of one of the static resources that needs to be loaded is displayed on the mobile Web page 13 and is a.css, which is used for limiting the page style.
Assuming that the version of the mobile Web page where the current mobile Web page 13 is located is version 1.0, when the page of version 1.0 is loaded and displayed, the mobile terminal may call the resource file a.css stored in the resource address 1 of the static resource server 11, and the resource address 1 at this time may be https:// a.b.c.com/manager/1.0/a/a.css, where 1.0 in the resource address 1 is a version number.
It is further assumed that the page of the new style released by the mobile Web page corresponds to version 2.0, the page style of the page of version 2.0 is style-improved relative to version 1.0, and the file content in the corresponding a.css file is also modified, which may be a code added with some new styles. The a.cs file of version 2.0 may be stored in the resource address 2 of the static resource server 11, and the mobile terminal acquires the latest a.cs file according to the resource address 2 when calling the resource file. However, the a.css file of version 2.0 and the a.css file of version 1.0 are named the same. Resource address 2 may be https:// a.b.c.com/manager/2.0/a/a.css, where 2.0 in resource address 2 is the version number.
As can be seen from the above, the static resource in the mobile Web page may have a plurality of different resource addresses, which are listed as the resource address changes due to the file version change, but in actual implementation, the resource address may also be changed due to other situations. However, for the mobile terminal, under the above version management mechanism, although the resource address changes, the called resources are all different versions of the same resource file, for example, all are a.css, only the address of the file changes, and the file content of the file is updated, one is an a.css file of version 1.0, and one is an a.css file of version 2.0; in other examples, it may be that the resource address has changed but the contents of the resource file have not been updated.
In the process of loading and displaying a mobile Web page, sometimes a static resource server cannot normally provide a static resource requested to be called, so that the normal use of a service function is influenced. For example, if a mobile Web page calls the a.css of the resource address 2 in the loading process, however, for some unknown reasons, the static resource server cannot normally return to the a.css, so that the Web page cannot be normally displayed, and the service function of the page is also affected and cannot normally operate. Generally, when a static resource on a calling server cannot return normally, a user may see a page without a style and being inoperable on the page, and when a developer tool is used to check the resource status of the page, a prompt of 404 is seen, that is, 404 represents that the server cannot provide information normally when a client browses a web page or acquires a resource, or the server cannot respond and does not know the reason. Invoking 404 the page static resource may affect the normal use of the page function.
In order to solve the above problem 404 and ensure that the business function of the page normally operates, fig. 2 illustrates a method for displaying a web page, which may include:
in step 200, when the page to be displayed is rendered, according to the second resource address, a request is made to the resource server to obtain the second version of the page static resource included in the page.
For example, assume that a Web page is loaded in the current mobile terminal APP, and the Web page contains some static resource files for defining page styles and interactions. In this step, the static resource server may be requested to call to obtain the static resource of the page according to the resource address included in the page.
For example, taking a.css in fig. 1 as an example, assuming that the current Web page corresponds to a page of version 2.0, a.css is requested from the server according to resource address 2. The resource address 2 may be referred to as a second resource address, that is, an address corresponding to a static resource currently being requested, and the a.css of version 2.0 may be referred to as a second version of the page static resource.
In step 202, when the resource server returns that the resource acquisition fails, a first resource address corresponding to the first version of the page static resource is acquired, where the first resource address is an address that is determined to be capable of providing the first version of the page static resource.
For example, the static resource server returns 404 that the a.css of resource address 2 cannot be retrieved for some unknown reason. Then, in this step, a first resource address corresponding to the a.cs of the first version may be obtained, where the first resource address is a determined address capable of stably providing a page static resource a.cs, that is, the a.cs may be obtained by the first resource address, but the obtained a.cs may be another version. For example, the first resource address may be resource address 1 in fig. 1, or another resource address not shown in fig. 1. It should be noted that, the reference to "second" or "first" in this example is only for distinguishing different resource addresses or different versions of the static resource in the same page, and has no other limiting effect.
In step 204, a request is made to the resource server to obtain a first version of the page static resource according to the first resource address.
In this step, the mobile terminal may request the resource server to obtain the page static resource according to the first resource address. For example, when a.css cannot be obtained by resource address 1 in fig. 1, a.css may be obtained again according to resource address 1.
In step 206, the first version of the page static resource fed back by the resource server is received and loaded to render and display the page.
Since the first resource address is an address that is determined to be able to provide the static resource of the page, the mobile terminal may receive the static resource, such as the above a.css, returned by the static resource server at this time, and load and display the static resource, so as to normally display the Web page.
According to the webpage display method, when the server returns that the resource acquisition fails, the resource is requested to the server through the first resource address, so that the static resource of the page can be acquired, and the service function of the page can run normally. Although it is possible that the returned resource file is not the file to be obtained when the resource file is initially requested according to the first resource address, for example, the files of the two addresses have some differences in page style, the method of this example can maximally ensure the normal operation of the service function, and sometimes the normal operation of the page function is more important than the update of the page style.
The above-described procedure for preventing 404 the condition by the first resource address is described in detail as an example. The mobile Web page can be loaded and displayed through a WebView component, and the WebView can be regarded as a browser for loading and displaying a webpage. The WebView can comprise web page engines Webcore and WebViewClient, wherein the WebCore can be a module which is positioned at a bottom layer (C/C + + layer) and is responsible for analyzing a web page, the WebViewClient can be a module which is positioned at an upper layer (Java layer) and is responsible for executing some calling requests, and when the Webcore needs to call some resources in the process of analyzing the web page, the WebViewClient can be informed to acquire the resources. The interaction of WebCore, WebViewClient and static resource server can be described below to illustrate how to load and display a mobile Web page to overcome the service function failure caused by 404. The method includes a normal call flow when the resource is normally acquired and a protection flow when the resource is acquired at 404.
FIG. 3 illustrates an example normal call flow during normal resource acquisition, which may include:
in step 300, the WebCore notifies the WebViewClient of the request for static resources, carrying the resource identifier of the requested page static resources.
In this step, when the WebCore parses the Web page and needs to request to acquire the static resource in the page, the webview client may be notified to acquire the resource, and the resource address is notified to the webview client.
In one example, WebCore may add a resource identification, which may be referred to as a resource, of the static resource of the request to the resource address. For example, assuming the resource address is https:// a.b.c.com/manager/1.0/a/a.cs, after increasing resource, the address could be https:// a.b.c.com/manager/1.0/a/a.cs? resource-key-a. In this example, a in the file name a.css of the resource file may be used as the resource, because different resource files generally have different file names, and using the file name as the resource may implement differentiation of different files, and implement unique identification of each resource file requested. Of course, the resource identifier may be set in other manners.
In step 302, the WebViewClient requests the resource server to obtain the page static resource according to the resource address.
For example, WebViewClient can be based on the above-mentioned address https:// a.b.c.com/manager/1.0/a/a.css? And (b) requesting the resource file a.css of the static resource by the static resource server.
In step 304, the resource server returns the static resource to WebViewClient normally.
In this example, the resource server may successfully return the page static resource, and based on this, the WebViewClient may also determine that the resource address on which the resource is requested in step 302 is an address determined to be capable of stably providing the page static resource.
In step 306, WebViewClient returns static resources to Webcore.
Webcore may receive a resource file of static resources and load the file to display pages normally.
In step 308, WebViewClient obtains the resource identification of the static resource.
In step 304, the WebViewClient has determined that the resource address on which the resource is requested is the address that can stably provide the static resource of the page, and in this step, the WebViewClient can obtain the resource identifier of the static resource. For example, the resource identification may be obtained from the resource address https:// a.b.c.com/manager/1.0/a/a.css? resource identification resource can be obtained from resource a.
In step 310, WebViewClient stores the corresponding relationship between the resource identifier and the resource address to a local cache.
For example, the correspondence stored by WebViewClient may be:
a——https://a.b.c.com/manager/1.0/a/a.css?resourcekey=a
the above correspondence shows that, for a page static resource whose resource key is a, one of the resource addresses capable of stably providing the resource is https:// a.b.c.com/manager/1.0/a/a.css? resource-key-a.
In the process shown in fig. 3, when the server returns the resource normally, the corresponding relationship between the resource and the stable resource address thereof may be stored in the local cache for use in the subsequent process shown in fig. 4. When the mobile terminal parses the page for multiple times, for example, when the user opens the APP for multiple times, to show the page, the page static resource of the page may be requested for multiple times, but the local cache may store a corresponding relationship.
Fig. 4 illustrates an example protection flow when an error code occurs to request the static resource to return 404, and the flow of fig. 4 may use the correspondence stored in fig. 3, where, in the example shown in fig. 3, the resource address https:// a.b.c.com/manager/1.0/a/a.css? resource is called as a first resource address, and the normally returned resource can be called as a first version of page static resource. As shown in fig. 4, the method of the present example may include:
in step 400, the WebCore notifies the WebViewClient of the request for static resources, carrying the resource identifier of the requested page static resources.
In this step, when the WebCore parses the Web page and needs to request to acquire the static resource in the page, the webview client may be notified to acquire the resource, and the resource address is notified to the webview client. The resource address in this step may be referred to as a second resource address, which may be https:// a.b.c.com/manager/2.0/a/a.cs? resource key a, that is, the second resource address is the address corresponding to the Web page of version 2.0, and the previous first resource address is version 1.0.
In step 402, the WebViewClient requests the resource server to obtain the second version of the page static resource according to the second resource address.
For example, WebViewClient can be based on the above-mentioned address https:// a.b.c.com/manager/2.0/a/a.css? And (b) requesting the resource file a.css of the static resource by the static resource server. Except that this a.css is a second version of a.css, which may not be the same version as the a.css obtained in the example of fig. 3, e.g., some changes are made to the specific style.
In step 404, the resource server returns 404 to WebViewClient.
In this example, the resource server may not find the page static resource.
In step 406, WebViewClient obtains the resource identifier from the second resource address.
For example, can be represented by https:// a.b.c.com/manager/2.0/a/a.css? And acquiring a resource identifier, namely resource.
In step 408, the WebViewClient obtains the corresponding first resource address from the local cache according to the resource identifier.
In this step, since the page static resource of the second version and the page static resource of the first version correspond to the same resource identifier, for example, the resource is a, the WebViewClient may request the local cache to obtain the first resource address corresponding to the resource.
In step 410, WebViewClient receives the first resource address returned by the local cache.
For example, the first resource address may be a ground in the correspondence stored in the flow of FIG. 3, https:// a.b.c.com/manager/1.0/a/a.cs? resource-key-a. I.e. an address that may be version 1.0.
In step 412, the WebViewClient requests the resource server to obtain the page static resource according to the first resource address.
In step 414, WebViewClient receives the resource file returned by the server.
Since the first resource address is an address determined to be capable of stably providing the resource, the WebViewClient can acquire the resource file when requesting the resource according to the first resource address. For example, when the resource file is not obtained at resource address 2 (second resource address) in fig. 1, the resource file may be obtained at resource address 1 (first resource address) because the address is an address to which a resource has been normally returned before.
In step 416, WebViewClient returns the resource file to Webcore.
In the step, the WebViewClient returns the resource file to the Webcore, so that the Webcore can load static resources and the page function can normally run.
In addition, the WebViewclient can also call a log reporting interface to report alarm information so as to inform a developer of the problem that the second resource address cannot acquire the resource file.
According to the webpage display method, when the server returns that the resource acquisition fails, the resource is requested to the server through the first resource address, so that the static resource of the page can be acquired, and the service function of the page can run normally.
In order to implement the method, one or more embodiments of the present specification further provide a web page display apparatus, as shown in fig. 5, the apparatus may include: a resource request module 51, an address acquisition module 52, a re-request module 53 and a resource receiving module 54.
The resource request module 51 is configured to, when a page to be displayed is rendered, request a resource server to acquire a second version of a page static resource included in the page according to a second resource address;
an address obtaining module 52, configured to obtain a first resource address corresponding to the first version of the page static resource when the resource server returns that resource obtaining fails, where the first resource address determines that the page static resource of the first version can be provided;
a re-request module 53, configured to request the resource server to obtain the page static resource of the first version according to the first resource address;
and the resource receiving module 54 is configured to receive and load the first version of the page static resource fed back by the resource server, so as to render and display the page.
In one example, as shown in FIG. 6, the apparatus further includes an address storage module 55.
The resource request module 51 is further configured to, before requesting the resource server to acquire the page static resource of the second version according to the second resource address, request the resource server to acquire the page static resource of the first version according to the first resource address;
an address storage module 55, configured to determine that the first resource address is an address for determining to provide the first version of the page static resource when the resource server successfully returns the page static resource, and store a corresponding relationship between a resource identifier of the page static resource and the first resource address.
In an example, the resource requesting module 51 is further configured to allocate a corresponding resource identifier for the page static resource, and set the resource identifier in the first resource address;
the address storage module 55 is specifically configured to obtain the resource identifier from the first resource address, and store a corresponding relationship between the resource identifier and the first resource address.
In an example, the address storage module 55 is specifically configured to store, in a local cache, a corresponding relationship between a resource identifier of the page static resource and a first resource address.
In an example, the address obtaining module 52 is configured to obtain the resource identifier from the second resource address, where the second resource address carries the resource identifier of the page static resource; acquiring the first resource address corresponding to the resource identifier according to the resource identifier; and the page static resource of the second version and the page static resource of the first version correspond to the same resource identifier.
For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, the functionality of the modules may be implemented in the same one or more software and/or hardware implementations in implementing one or more embodiments of the present description.
The execution sequence of each step in the flow shown in the above method embodiment is not limited to the sequence in the flow chart. Furthermore, the description of each step may be implemented in software, hardware or a combination thereof, for example, a person skilled in the art may implement it in the form of software code, and may be a computer executable instruction capable of implementing the corresponding logical function of the step. When implemented in software, the executable instructions may be stored in a memory and executed by a processor in the device.
For example, corresponding to the above-mentioned web page display method, one or more embodiments of the present specification also provide a web page display apparatus, which may include a processor, a memory, and computer instructions stored in the memory and executable on the processor, where the processor is configured to execute the instructions to implement the following steps: when the page to be displayed is rendered, according to the second resource address, requesting the resource server to acquire the page static resource of the second version; when the resource server returns that the resource acquisition fails, acquiring a first resource address corresponding to the page static resource of a first version, wherein the first resource address is an address for determining to provide the page static resource of the first version; requesting a resource server to acquire the page static resource of the first version according to the first resource address; and receiving and loading the first version of the page static resource fed back by the resource server so as to render and display the page.
The apparatuses or modules illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
One skilled in the art will recognize that one or more embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
One or more embodiments of the present description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. One or more embodiments of the specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. Especially, for the server device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for relevant points, refer to part of the description of the method embodiment.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The above description is only exemplary of the preferred embodiment of one or more embodiments of the present disclosure, and is not intended to limit the present disclosure, so that any modification, equivalent replacement, or improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.