Page rendering method, device, electronic device and storage medium
By detecting the completion status of static resource files and business resource files, triggering target events to ensure that the static resource files have completed running before running the business resource files, the page rendering problem caused by the static resource files not being generated is solved, and the page rendering is realized. Successful completion and improvement of user experience.
Patent Information
- Application Number
- CN202010273940.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-09
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-04-09
AI Technical Summary
During the page rendering process, when the static resource file is not generated, an error occurs in the operation of the business resource file, causing the page to fail to complete rendering and stay in the state of displaying the placeholder image.
By detecting the completion status of static resource files and business resource files, target events are triggered to ensure that the static resource files have completed running before running the business resource files, thereby avoiding business resource file errors caused by incomplete running of the static resource files.
Ensure that page rendering is completed smoothly, avoid the page remaining in the state of displaying placeholder images, and improve user experience.
Smart Images

Figure CN113515328B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for page rendering. Background Art
[0002] In page display technology, in order to optimize the user experience, before the user waits for the final page rendering to be completed, a placeholder image is usually displayed to ease the user's waiting process. After the page renders the placeholder image, the static resource files and business resource files are run to obtain the final rendered page.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Since the operation of business resource files depends on static resource files, static resource files are usually generated before business resource files. However, in some scenarios, static resource files are not generated when business resource files are running, which leads to errors in the operation of business resource files, and the page stays in the state of displaying placeholders, which makes the page unable to render. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method, device, system and storage medium for page rendering, which can avoid the problem that static resource files have not been generated when business resource files are running, thereby causing business resource files to run incorrectly and the page cannot be rendered.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for page rendering is provided.
[0007] A page rendering method according to an embodiment of the present invention includes: rendering a placeholder of a page to be displayed according to placeholder information in page data of the page to be displayed; acquiring and running a static resource file according to static resource information in the page data, and acquiring a business resource file according to the business resource information; detecting whether a target event is triggered, wherein the target event is triggered when the static resource file is executed and the business resource file is acquired; if so, rendering the page to be displayed by using the result of running the business resource file, so that the rendered page to be displayed replaces the placeholder.
[0008] In one embodiment, before detecting whether the target event is triggered, the method further includes:
[0009] After the static resource file is run and the business resource file is acquired, the value of the target parameter is changed to the target value;
[0010] The detecting whether the target event is triggered includes:
[0011] Detecting whether the value of the target parameter is the target value;
[0012] If so, the target event is triggered; if not, the target event is not triggered.
[0013] In yet another embodiment, the target parameters include a first target parameter and a second target parameter, and the target value includes a first target and a second target value;
[0014] Changing the value of the target parameter to the target value includes:
[0015] When the static resource file is finished running, the value of the first target parameter is changed to the first target value;
[0016] When the business resource file is acquired, the value of the second target parameter is changed to the second target value.
[0017] In yet another embodiment, the target event includes a first event and a second event, the first event indicates that the static resource file is completed, and the second event indicates that the business resource file is completed;
[0018] The detecting whether the target event is triggered includes:
[0019] Detecting whether both the first event and the second event are triggered;
[0020] If so, the target event is triggered; if not, the target event is not triggered.
[0021] In yet another embodiment, the first event indicates that the static resource file is executed successfully, and the second event indicates that the business resource file is acquired successfully;
[0022] Before detecting whether the target event is triggered, the method further includes:
[0023] When the static resource file is finished running, the first event is triggered;
[0024] When the business resource file is acquired, triggering the second event;
[0025] When it is detected that both the first event and the second event are triggered, the target event is triggered.
[0026] In yet another embodiment, before rendering the placeholder image of the page to be displayed according to the placeholder image information in the page data of the page to be displayed, the method further includes:
[0027] Configuring a first event in the page data, wherein the first event is used to be triggered after the static resource file is finished running;
[0028] Setting a second event after the business resource file is finished configuring, the second event being used to be triggered after the business resource file is finished acquiring;
[0029] A target event is configured, where the target event is used to be triggered after both the first event and the second event are triggered.
[0030] To achieve the above objective, according to another aspect of the present invention, a device for page rendering is provided.
[0031] A page rendering device of the present invention includes: a rendering unit, which is used to render a placeholder of a page to be displayed according to the placeholder information in the page data of the page to be displayed; a processing unit, which is used to obtain and run static resource files according to the static resource information in the page data, and to obtain business resource files according to the business resource information; a detection unit, which is used to detect whether a target event is triggered, wherein the target event is triggered when the static resource file is run and the business resource file is obtained; if so, the rendering unit is further used to render the page to be displayed by running the result of the business resource file, so that the rendered page to be displayed replaces the placeholder.
[0032] In one embodiment, it further includes:
[0033] An adjustment unit, configured to change the value of the target parameter to a target value after the static resource file is run and the business resource file is acquired;
[0034] The detection unit is specifically used for:
[0035] Detecting whether the value of the target parameter is the target value;
[0036] If so, the target event is triggered; if not, the target event is not triggered.
[0037] In yet another embodiment, the target parameters include a first target parameter and a second target parameter, and the target value includes a first target and a second target value;
[0038] The adjustment unit is specifically used for:
[0039] When the static resource file is finished running, the value of the first target parameter is changed to the first target value;
[0040] When the business resource file is acquired, the value of the second target parameter is changed to the second target value.
[0041] In yet another embodiment, the target event includes a first event and a second event, wherein the first event being triggered indicates that the static resource file is executed successfully, and the second event being triggered indicates that the business resource file is acquired successfully;
[0042] The detection unit is specifically used for:
[0043] Detecting whether both the first event and the second event are triggered;
[0044] If so, the target event is triggered; if not, the target event is not triggered.
[0045] In yet another embodiment, the first event indicates that the static resource file is executed successfully, and the second event indicates that the business resource file is acquired successfully;
[0046] The device further includes a triggering unit, which is used to: trigger the first event when the static resource file is finished running;
[0047] When the business resource file is acquired, triggering the second event;
[0048] When it is detected that both the first event and the second event are triggered, the target event is triggered.
[0049] In yet another embodiment, the apparatus further comprises a configuration unit, configured to:
[0050] Configuring a first event in the page data, wherein the first event is used to be triggered after the static resource file is finished running;
[0051] Setting a second event after the business resource file is finished configuring, the second event being used to be triggered after the business resource file is finished acquiring;
[0052] A target event is configured, where the target event is used to be triggered after both the first event and the second event are triggered.
[0053] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.
[0054] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the page rendering method provided by the embodiment of the present invention.
[0055] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0056] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, the method for page rendering provided by the embodiment of the present invention is implemented.
[0057] One embodiment of the above invention has the following advantages or beneficial effects: In the embodiment of the present invention, after the placeholder image is rendered on the page to be displayed, the static resource file and the business resource file can be obtained respectively, and the static resource file can be run, and then the process of running the static resource file and obtaining the business resource file can be judged by detecting whether the target event is triggered, and the business resource file can be run again after the target event is triggered to achieve the rendering of the page to be displayed. In this way, in the embodiment of the present invention, it is determined whether the static resource file has been completed and whether the business resource file has been obtained by detecting whether the target event is triggered, and after the static resource file has been completed and the business resource file has been obtained, the business resource file is run, thereby ensuring that the static resource file has been completed when the business resource file is run, avoiding the problem of business resource file running errors due to the incomplete operation of the static resource file, and thus avoiding the problem that the page stays in the state of displaying the placeholder image and cannot be rendered.
[0058] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0060] Figure 1 is a schematic diagram of a main process of a method for page rendering according to an embodiment of the present invention;
[0061] Figure 2 is a schematic diagram of another main process of the method for page rendering according to an embodiment of the present invention;
[0062] Figure 3 is a schematic diagram of main units of a device for page rendering according to an embodiment of the present invention;
[0063] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0064] Figure 5 It is a schematic diagram of the structure of a computer system suitable for implementing the embodiment of the present invention. DETAILED DESCRIPTION
[0065] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0066] It should be pointed out that the embodiments of the present invention and the features in the embodiments may be combined with each other if there is no conflict.
[0067] An embodiment of the present invention provides a method for page rendering, which can be used in a scenario where page rendering is performed after page data of a page to be displayed is obtained. Specifically, in an embodiment of the present invention, a system architecture applicable to a method for page rendering may include a client and a server, wherein the client and the server interact with each other, the client may send a page display request to the server, and the server returns the page data of the page to be displayed requested by the client according to the request sent by the client, and after receiving the page data, the client may render the page to be displayed according to the page data, thereby realizing page display.
[0068] In an embodiment of the present invention, in order to improve the user experience, the client will first render a placeholder in the page to be displayed, so as to ease the user's mood of waiting for the page to be displayed. After displaying the placeholder, the client will obtain and run the static resource file and the business resource file, so as to realize the content to be displayed for the rendering of the page to be displayed. Since the business resource file needs to rely on the static resource file when running, in order to ensure that the static resource file has been run when the business resource file is running, in an embodiment of the present invention, trigger events and monitoring events are set in the business resource file and the rendering process, so as to realize that the target event can be triggered after the static resource file is obtained and run, and the business resource file is obtained. The target event is triggered to indicate that the static resource file is obtained and run, and the business resource file is obtained, that is, when the static resource file is run and the business resource file is obtained, after the client detects the triggering target event, the business resource file can be run, so that the running order of the static resource file and the business resource file can be guaranteed, that is, to avoid the problem that the business resource file fails to complete the rendering due to the failure of the static resource file to run when the business resource file is executed.
[0069] The embodiment of the present invention provides a method for page rendering, which can be executed by a client, such as Figure 1 As shown, the method includes the following steps.
[0070] S101: Rendering a placeholder image of a page to be displayed according to placeholder image information in page data of the page to be displayed.
[0071] When the client needs to display a page, it can send a page request of the page to be displayed to the server to request the page data of the page to be displayed. The server sends the page data of the page to be displayed to the client according to the page request of the client. Usually, the page data returned by the server is HTML. After receiving the page data, the client can first render the placeholder according to the placeholder information therein, so that the page to be displayed displays the placeholder.
[0072] In the embodiment of the present invention, the placeholder image may include multiple types, for example, the placeholder image may specifically be a skeleton screen.
[0073] S102: Obtain and run static resource files according to the static resource information in the page data, and obtain business resource files according to the business resource information.
[0074] Among them, after the client renders the placeholder image, the client can obtain the static resource file according to the static resource information in the page data, and run the static resource file after obtaining the static resource file, and the client can also obtain the business resource file according to the business resource information. Since the operation of the business resource file depends on the static resource file, after obtaining the business resource file, it is necessary to first determine whether the static resource file has completed the operation, and then run the business resource file after determining that the static resource file has completed the operation.
[0075] In an embodiment of the present invention, this step can be specifically performed as follows: generating static resource tags and business resource tags based on the static resource information and business resource information in the page data; obtaining and running static resource files based on the static resource tags, and obtaining business resource files based on the business resource tags.
[0076] The static resource information may include the code of the static resource, and a static resource tag may be generated by running the static resource code. The static resource tag includes a link for obtaining the static resource file, so the client can obtain the static resource file according to the static resource tag. The business resource information may include the code of the business resource, and a business resource tag may be generated by running the business resource code. The business resource tag includes a link for obtaining the business resource file, so the client can obtain the business resource file according to the business resource tag.
[0077] After the client generates the static resource tags and business resource tags, it can place them at the bottom of the tags in the HTML file to facilitate the running of the static resource tags and business resource tags.
[0078] It should be noted that, in the embodiment of the present invention, the static resource files may include JS (JavaScript, a lightweight, interpreted or just-in-time compiled programming language with function priority) files and CSS (Cascading Style Sheets, Cascading Style Sheets) files.
[0079] S103: Detect whether the target event is triggered.
[0080] The triggering of the target event indicates that the static resource file is running and the business resource file is acquired. The target event is pre-configured.
[0081] In the embodiment of the present invention, the target event can be triggered after the static resource file is run and the business resource file is acquired. Therefore, in this step, the client can determine whether the static resource file is run and the business resource file is acquired by detecting whether the target event is triggered. When the target event is triggered, it means that the static resource file is run and the business resource file is acquired; when the target event is not triggered, it means that the static resource file is not run or the business resource file is not acquired. At this time, you can wait until the target event is detected to be triggered before executing the subsequent steps.
[0082] In one implementation of the present invention, whether the target event is triggered can be reflected by adjusting the value of the target parameter corresponding to the target event. Specifically, the parameter value when the target event is not triggered can be a default value, and the parameter value when the target event is triggered can be a target value, and the default value is different from the target value.
[0083] Therefore, after executing step S102, since the static resource file has been completed and the business resource file has been acquired, the value of the target parameter can be changed to the target value. In this step, the value of the target parameter can also be detected to determine whether the target event is triggered. The specific process is: detect whether the value of the target parameter is the target value; if so, the target event is triggered; if not, the target event is not triggered. That is, if the value of the target parameter is detected to be the target value, it means that the static resource file has been completed and the business resource file has been acquired; if the value of the target parameter is detected to be not the target value, it means that the static resource file has not been completed or the business resource file has not been acquired.
[0084] Specifically, in an embodiment of the present invention, the target parameter may further include a first target parameter and a second target parameter, and the target value includes a first target value and a second target value. The step of changing the value of the target parameter to the target value is specifically performed as follows: when the static resource file is run to completion, the value of the first target parameter is changed to the first target value; when the business resource file is acquired to completion, the value of the second target parameter is changed to the second target value.
[0085] The value of the first target parameter is used to indicate whether the static resource file is running. If the value of the first target parameter is the first target value, it indicates that the static resource file is running. If the value of the first target parameter is not the first target value, it indicates that the static resource file is not running. The value of the second target parameter is used to indicate whether the business resource file is acquired. If the value of the second target parameter is the second target value, it indicates that the business resource file is acquired. If the value of the second target parameter is not the second target value, it indicates that the business resource file is not acquired. Therefore, in an embodiment of the present invention, when the static resource file is running, the value of the first target parameter is changed to the first target value, and when the business resource file is acquired, the value of the second target parameter is changed to the second target value, so as to facilitate the detection of subsequent target events. The first target value and the second target value may be the same or different.
[0086] In another implementation of the embodiment of the present invention, the completion of the running of the static resource file and the completion of the acquisition of the business resource file can be split into two events for separate control. Specifically, the target event may include a first event and a second event, wherein the first event being triggered indicates that the running of the static resource file is completed, and the second event being triggered indicates that the acquisition of the business resource file is completed.
[0087] Based on this, this step can be specifically performed as follows: detecting whether both the first event and the second event are triggered; if so, the target event is triggered; if not, the target event is not triggered.
[0088] After the client completes running the static resource file, the client can trigger the first event, so whether the static resource file is running is determined by detecting whether the first event is triggered. After the client completes acquiring the business resource file, the client can trigger the second event, so whether the business resource file is acquired is determined by detecting whether the second event is triggered. In this step, detecting whether the target event is triggered can be achieved by detecting whether both the first event and the second event are triggered. The triggering of both the first event and the second event indicates that the static resource file is running and the business resource file is acquired.
[0089] In an embodiment of the present invention, static resource files may include JS files and CSS files, and the first event includes a JS file running completion event and a CSS file running completion event, so detecting whether the first event and the second event are both triggered is specifically performed as follows: detecting whether the JS file running completion event, the CSS file running completion event and the second event are both triggered.
[0090] In another implementation of the embodiment of the present invention, the first event can be configured to be triggered to indicate that the static resource file is running, the second event can be configured to be triggered to indicate that the business resource file is acquired, and the target event can be configured to be triggered when both the first event and the second event are triggered. Therefore, before this step, the client can trigger the first event when the static resource file is running, trigger the second event when the business resource file is acquired, and trigger the target event when it is detected that both the first event and the second event are triggered. Then, in this step, it can be detected whether the target event is triggered.
[0091] In the embodiment of the present invention, in order to realize the above process, the page data can be configured during data development. Specifically, a first event can be configured in the page data, and the first event is used to be triggered after the static resource file is run; a second event can be configured at the end of the business resource file, and the second event is used to be triggered after the business resource file is obtained; a target event can be configured in the page data, and the target event is used to be triggered after both the first event and the second event are triggered.
[0092] Since the business resource file cannot be run immediately after successful acquisition, the second event is configured at the end of the code in the business resource file so that the second event can be triggered after the business resource file is acquired. At the same time, since the business resource file can only be run after the target event is triggered, it is necessary to configure a listening event at the front of the code in the business resource file to detect whether the target event is triggered, and run the business resource file after the target event is triggered. Since the static resource file runs directly after acquisition, the logic for triggering the first event can be directly configured in the page data, that is, the first event is configured in the page data so that the first event is triggered after the static resource file is run. After both the first event and the second event are triggered, the target event can be triggered, so the logic for triggering the target event is configured in the page data.
[0093] S104: If yes, the page to be displayed is rendered by running the result of the business resource file, so that the rendered page to be displayed replaces the placeholder image.
[0094] Among them, after step S103 detects whether the target event is triggered, if it is determined that the target event is triggered, it means that the business resource file can be run, and the business resource file can be run at this time, and the page to be displayed is rendered according to the result of running the business resource file. Since the placeholder image is displayed in the page to be displayed by executing step S101, after the page to be displayed is rendered in this step, the rendered content will replace the placeholder image.
[0095] In an embodiment of the present invention, whether the static resource file has completed running and whether the business resource file has been acquired is determined by detecting whether the target event is triggered, and after the static resource file has completed running and the business resource file has been acquired, the business resource file is run, thereby ensuring that the static resource file has completed running when the business resource file is running, thereby avoiding the problem of business resource file running errors due to incomplete running of the static resource file, and further avoiding the problem of the page staying in the state of displaying a placeholder image and being unable to complete rendering.
[0096] In the embodiment of the present invention, the static resource file includes dependent JS files and CSS files, and the business resource file is a business JS file. And the configuration dependent JS file is run to complete the trigger event C, the parameter X in the change event C is the target value, the CSS file is run to complete the trigger event C, the parameter Y in the change event C is the target value, the business JS file is obtained and the event B is triggered, and after the trigger event B is triggered, the event C is triggered, and the parameter Z in the change event C is the target value, and in the event C, the parameters X, Y, and Z are all the target values. After the target value, the event A is triggered, and the business JS file is run after the event A is triggered. Figure 1 The illustrated embodiment is described in detail.
[0097] In the above configuration, event B needs to be configured in the code of the business JS file, that is, add event B at the end of the code in the business JS file, so that event B is triggered after the business JS file is obtained. At the same time, the monitoring logic needs to be configured at the front of the code in the business JS file to detect whether event A is triggered, so that the business JS file can be run after event A is triggered. In addition, the configuration monitoring function of the page data is to detect events such as the completion of the dependent JS file acquisition and operation, the completion of the CSS file operation, the triggering of event B, and the triggering of event C. When the completion of the dependent JS file acquisition and operation is detected, the parameter X in event C is changed to the target value; when the completion of the CSS file acquisition and operation is detected, the parameter Y in event C is changed to the target value; when the event B is detected to be triggered, the parameter Z in event C is changed to the target value; when the event C is detected to be triggered, that is, the values of the parameters X, Y, and Z in event C are all target values, event A is triggered.
[0098] It should be noted that, in an embodiment of the present invention, the above configuration process can be developed by Webpack packaging dependent JS files, CSS files and business JS files, wherein the configuration of the business JS code can use NodeJS reading and writing technology to complete the code configuration in the business JS file, that is, add event monitoring logic at the front of the code of the business JS file to monitor event A, and add trigger event B at the end of the business JS code. The reason for adding trigger event B at the end of the business code is that it is necessary to wait until the business code is loaded before obtaining the execution function defined by the monitoring event A, otherwise it may not be possible to obtain the execution function of the monitoring event A and report an error. Through the above processing, the business JS code generated by Webpack packaging will be wrapped by the monitoring event A, so that after the client obtains the business JS file, it will not immediately execute the business JS file. Add trigger event B at the end of the business JS file, so that event B will be triggered after the business JS file is obtained.
[0099] Combine the following Figure 1 The embodiment shown and the above description specifically illustrate the method for page rendering in the embodiment of the present invention. Figure 2 As shown, the method includes the following steps.
[0100] S201: Obtaining page data of a page to be displayed from a server.
[0101] Among them, the client can send a page request to the server according to the instruction input by the user. The page request may include the URL of the page to be displayed. After receiving the page request, the server will return the page data of the page to be displayed to the client. The page data is usually html.
[0102] It should be noted that the page data returned by the server has already completed the above configurations on triggering events and monitoring functions.
[0103] S202: Rendering a skeleton screen in the page to be displayed.
[0104] After receiving the page data, the client may first render the skeleton screen according to the skeleton screen information in the page data, so that the page to be displayed displays the skeleton screen.
[0105] In the embodiment of the present invention, in order to relieve the user's mood of waiting for page rendering, the skeleton screen can be rendered first, and then the static resource files and business resource files can be obtained and run.
[0106] S203: Generate dependent JS tags, CSS tags, and business JS tags and add them to the bottom of the body tag of the page data.
[0107] Among them, after the skeleton screen is rendered on the display page, dependent JS tags, CSS tags, and business JS tags can be dynamically generated and added to the bottom of the tags of the page data.
[0108] Since the skeleton screen is rendered first in the embodiment of the present invention, the dependent JS tags, CSS tags, and business JS tags all need to be generated by the client during the page rendering process, and the generated dependent JS tags, CSS tags, and business JS tags are added to the bottom of the tag of the page data html. These tags include information such as the connection to obtain the corresponding file, so the client can load the corresponding file by running these tags.
[0109] S204: Obtain and run dependent JS files and CSS files, and obtain business JS files.
[0110] In this step, by running the dependent JS tag, CSS tag and business JS tag respectively, the dependent JS file, CSS file and business JS can be obtained. The dependent JS file and CSS file are directly run after they are obtained, while after the business JS file is obtained, it needs to wait for event A to be triggered before running.
[0111] S205: Check that the dependent JS file has completed running, and change the value of parameter X in event C to the target value.
[0112] Among them, a monitoring function is configured in the page data, so after detecting that the dependent JS file has finished running, the trigger event C can be executed, that is, the value of the parameter X in the event C is changed to the target value.
[0113] S206: Detect that the CSS file has been run, and change the value of parameter Y in event C to the target value.
[0114] Among them, a monitoring function is configured in the page data, so after detecting that the CSS file has been run, the trigger event C can be executed, that is, the value of the parameter Y in the event C is changed to the target value.
[0115] S207: Event B is triggered after the detection of the business JS file is completed.
[0116] If event B is configured in the code of the business JS file, event B can be triggered after the business JS file is obtained.
[0117] In the embodiment of the present invention, the method of triggering event B may be to adjust parameters included in event B to preset values, so as to indicate that event B is triggered.
[0118] S208: After the detection event B is triggered, the value of the parameter Z in the change event C is changed to the target value.
[0119] Among them, a monitoring function is configured in the page data, so after detecting that event B is triggered, the trigger event C can be executed, that is, the value of parameter Z in event C is changed to the target value.
[0120] In the embodiment of the present invention, the specific value of the target value can be set according to the scenario, for example, it can be set to true.
[0121] S209: After detecting event C is triggered, event A is triggered.
[0122] Event C is triggered when the values of parameters X, Y and Z in event C are all target values. Therefore, after detecting that the values of parameters X, Y and Z in event C are all target values, it can be determined that time C is triggered, and event A can be triggered at this time.
[0123] S210: Execute the business JS file after the detection event A is triggered.
[0124] The code in the business JS file configures the monitoring event of time A, so after the monitoring event detects that event A is triggered, the business JS file can be run to obtain the result of running the business JS file.
[0125] S211: Rendering the page to be displayed according to the result of running the business JS file.
[0126] When the result of running the business JS file is obtained, the page to be displayed is rendered, so that the skeleton screen initially displayed is replaced in the page to be displayed, and the content to be displayed is displayed.
[0127] In an embodiment of the present invention, whether the static resource file has completed running and whether the business resource file has been acquired is determined by detecting whether the target event is triggered, and after the static resource file has completed running and the business resource file has been acquired, the business resource file is run, thereby ensuring that the static resource file has completed running when the business resource file is running, thereby avoiding the problem of business resource file running errors due to incomplete running of the static resource file, and further avoiding the problem of the page staying in the state of displaying a placeholder image and being unable to complete rendering.
[0128] In order to solve the problems existing in the prior art, an embodiment of the present invention provides a device 300 for page rendering, such as Figure 3 As shown, the device 300 includes:
[0129] The rendering unit 301 is used to render a placeholder image of the page to be displayed according to the placeholder image information in the page data of the page to be displayed;
[0130] The processing unit 302 is used to obtain and run static resource files according to the static resource information in the page data, and obtain business resource files according to the business resource information;
[0131] A detection unit 303 is used to detect whether a target event is triggered, wherein the target event is triggered when the static resource file is run and the business resource file is acquired;
[0132] If so, the rendering unit 301 is further configured to render the page to be displayed by running the result of the business resource file, so that the rendered page to be displayed replaces the placeholder image.
[0133] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 2 The method of the illustrated embodiment is the same and will not be repeated here.
[0134] In an implementation manner of the embodiment of the present invention, the apparatus 300 further includes:
[0135] An adjustment unit, configured to change the value of the target parameter to a target value after the static resource file is run and the business resource file is acquired;
[0136] The detection unit 303 is specifically used for:
[0137] Detecting whether the value of the target parameter is the target value;
[0138] If so, the target event is triggered; if not, the target event is not triggered.
[0139] In another implementation of the embodiment of the present invention, the target parameter includes a first target parameter and a second target parameter, and the target value includes a first target and a second target value;
[0140] The adjustment unit is specifically used for:
[0141] When the static resource file is finished running, the value of the first target parameter is changed to the first target value;
[0142] When the business resource file is acquired, the value of the second target parameter is changed to the second target value.
[0143] In another implementation of the embodiment of the present invention, the target event includes a first event and a second event, the first event being triggered indicates that the static resource file is executed, and the second event being triggered indicates that the business resource file is acquired;
[0144] The detection unit 303 is specifically used for:
[0145] Detecting whether both the first event and the second event are triggered;
[0146] If so, the target event is triggered; if not, the target event is not triggered.
[0147] In another implementation of the embodiment of the present invention, the first event indicates that the static resource file is completed, and the second event indicates that the business resource file is completed;
[0148] The device 300 further includes a trigger unit, which is used to:
[0149] When the static resource file is finished running, the first event is triggered;
[0150] When the business resource file is acquired, triggering the second event;
[0151] When it is detected that both the first event and the second event are triggered, the target event is triggered.
[0152] In yet another embodiment, the apparatus 300 further includes a configuration unit, configured to:
[0153] Configuring a first event in the page data, wherein the first event is used to be triggered after the static resource file is finished running;
[0154] Setting a second event after the business resource file is finished configuring, the second event being used to be triggered after the business resource file is finished acquiring;
[0155] A target event is configured, where the target event is used to be triggered after both the first event and the second event are triggered.
[0156] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 1 or Figure 2 The method of the illustrated embodiment is the same and will not be repeated here.
[0157] In an embodiment of the present invention, whether the static resource file has completed running and whether the business resource file has been acquired is determined by detecting whether the target event is triggered, and after the static resource file has completed running and the business resource file has been acquired, the business resource file is run, thereby ensuring that the static resource file has completed running when the business resource file is running, thereby avoiding the problem of business resource file running errors due to incomplete running of the static resource file, and further avoiding the problem of the page staying in the state of displaying a placeholder image and being unable to complete rendering.
[0158] According to an embodiment of the present invention, the present invention also provides an electronic device and a readable storage medium.
[0159] The electronic device of the present invention comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the page rendering method provided by an embodiment of the present invention.
[0160] Figure 4 An exemplary system architecture 400 is shown to which the method or apparatus for page rendering according to an embodiment of the present invention may be applied.
[0161] like Figure 4 As shown, the system architecture 400 may include at least one terminal device ( Figure 4 401, terminal device 402 and terminal device 403 are shown in the figure). Taking terminal device 401 as an example for explanation, terminal device 401 can be various electronic devices with a display screen and supporting page display, including but not limited to smart phones, tablet computers, laptop portable computers and desktop computers, etc., and the terminal device 401 can realize the page rendering function when the page is displayed by installing a client or application for page display. When the terminal device 401 is running, it can send a page data request to the server 405 to obtain the page data of the page to be displayed from the server 405, and render the page data.
[0162] The system architecture 400 may also include a server 405, which may be a background management server (just an example) that provides support for pages browsed by users using terminal devices 401, 402, and 403. The background management server may analyze and process received data such as page data requests, and feed back the processing results (such as page data - just an example) to the terminal device.
[0163] like Figure 4 As shown, the system architecture 400 may also include a network 404. The network 404 is used to provide a medium for a communication link between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc. Users can use the terminal devices 401, 402, 403 to interact with the server 405 through the network 404 to receive or send messages, etc.
[0164] It should be noted that the page rendering method provided in the embodiment of the present invention is generally executed by the terminal devices 401 , 402 , 403 , and accordingly, the page rendering apparatus is generally disposed in the terminal devices 401 , 402 , 403 .
[0165] It should be understood that Figure 4The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0166] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 suitable for implementing an embodiment of the present invention. Figure 5 The computer system shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0167] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0168] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0169] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0170] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0171] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a unit, a program segment, or a part of a code, and the above-mentioned unit, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0172] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be arranged in a processor. For example, they may be described as: a processor includes a rendering unit, a processing unit, and a detection unit. The names of these units do not, in some cases, constitute limitations on the units themselves. For example, a rendering unit may also be described as a "unit of the function of a rendering unit".
[0173] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device executes the page rendering method provided by the present invention.
[0174] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for page rendering, characterized in that: include: Rendering a placeholder image of the page to be displayed according to the placeholder image information in the page data of the page to be displayed; Obtaining and running static resource files according to the static resource information in the page data, and obtaining business resource files according to the business resource information; Detecting whether a target event is triggered, wherein the target event is triggered when the static resource file is run and the business resource file is acquired; If yes, the page to be displayed is rendered by running the result of the business resource file, so that the rendered page to be displayed replaces the placeholder image; Before detecting whether the target event is triggered, the method further includes: After the static resource file is run and the business resource file is acquired, the value of the target parameter is changed to the target value; The detecting whether the target event is triggered includes: Detecting whether the value of the target parameter is the target value; If so, the target event is triggered; if not, the target event is not triggered.
2. The method according to claim 1, characterized in that The target parameters include a first target parameter and a second target parameter, and the target value includes a first target value and a second target value; Changing the value of the target parameter to the target value includes: When the static resource file is finished running, the value of the first target parameter is changed to the first target value; When the business resource file is acquired, the value of the second target parameter is changed to the second target value.
3. The method according to claim 1, characterized in that: The target event includes a first event and a second event, wherein the first event being triggered indicates that the static resource file is running successfully, and the second event being triggered indicates that the business resource file is acquiring successfully; The detecting whether the target event is triggered includes: Detecting whether both the first event and the second event are triggered; If so, the target event is triggered; if not, the target event is not triggered.
4. The method according to claim 3, characterized in that The first event indicates that the static resource file has been run, and the second event indicates that the business resource file has been acquired; Before detecting whether the target event is triggered, the method further includes: When the static resource file is finished running, the first event is triggered; When the business resource file is acquired, triggering the second event; When it is detected that both the first event and the second event are triggered, the target event is triggered.
5. The method according to claim 4, characterized in that Before rendering the placeholder image of the page to be displayed according to the placeholder image information in the page data of the page to be displayed, the method further includes: Configuring a first event in the page data, wherein the first event is used to be triggered after the static resource file is finished running; Setting a second event after the business resource file is finished configuring, the second event being used to be triggered after the business resource file is finished acquiring; A target event is configured in the page data, and the target event is used to be triggered after both the first event and the second event are triggered.
6. A device for page rendering, characterized in that: include: A rendering unit, configured to render a placeholder image of the page to be displayed according to the placeholder image information in the page data of the page to be displayed; A processing unit, used to obtain and run static resource files according to the static resource information in the page data, and to obtain business resource files according to the business resource information; A detection unit, used to detect whether a target event is triggered, wherein the target event is triggered when the static resource file is run and the business resource file is acquired; If yes, the rendering unit is further used to render the page to be displayed by running the result of the business resource file, so that the rendered page to be displayed replaces the placeholder image; Also includes: A changing unit, configured to change the value of the target parameter to the target parameter after the static resource file is run and the business resource file is acquired; The detection unit is specifically used for: Detecting whether the value of the target parameter is the target parameter; If so, the target event is triggered; if not, the target event is not triggered.
7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Static resource weight removing method, and static resource management method and device
CN104714965A
Loading method and device of system static resources
CN106293675A
