A method and apparatus for page loading
By setting an intermediate loading file during the page loading process, loading the intermediate file first and repeatedly calling it to obtain the floor loading results, the loading failure problem caused by asynchronous loading is solved, and efficient and reliable page loading is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-06-29
- Publication Date
- 2026-05-19
AI Technical Summary
In existing technologies, during page loading, there is a problem where the page template is loaded first and then the floor interface is called before the floor is fully loaded, resulting in loading failure. Furthermore, the interface is only called once during page loading, which cannot improve the loading failure situation.
By setting an intermediate loading file corresponding to each floor, the intermediate loading file is loaded first, and then the loading result of the floor loading file is obtained using the intermediate loading file. This includes repeating the call and using a backup call strategy when loading fails, to ensure that the page loads successfully.
It effectively solves the problem of page loading failure, greatly reduces the probability of page loading failure, and improves the reliability and efficiency of loading.
Smart Images

Figure CN114925305B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for loading pages. Background Technology
[0002] During the current page loading process, the JavaScript files for the specified floors are obtained through an API. The page template and the script files for each floor are then loaded sequentially or asynchronously. In the sequential loading case, each floor must be loaded first, followed by the page template. This means that while loading the page template, the pre-loaded floors can be successfully accessed via the floor's API, and then displayed in the corresponding area of the page, avoiding loading failures.
[0003] However, in asynchronous loading, the question arises about whether to load the page template first or the floor list first. If the floor list API is called after the page template is loaded to retrieve the floor list loading results, but the floor list hasn't finished loading (i.e., no floor list has been loaded), then loading will fail. Furthermore, since the API is only called once during page loading, this loading failure cannot be mitigated. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a method and apparatus for page loading. By setting an intermediate loading file corresponding to a floor, the intermediate loading file can be loaded first, and then the loading result corresponding to the floor loading file can be obtained using the intermediate loading file. This solves the problem of loading failure caused by directly obtaining the loading result corresponding to the floor loading file from the page loading file.
[0005] To achieve the above objectives, according to one aspect of the present invention, a method for loading a page is provided.
[0006] An embodiment of the present invention provides a method for loading a page, comprising: obtaining a floor loading file and an intermediate loading file corresponding to one or more floors of a page to be loaded; obtaining a first loading result corresponding to the floor loading file using the intermediate loading file; and loading the page according to the first loading result.
[0007] Optionally, the method further includes: if the first loading result is a loading failure, after a preset time period, reusing the calling function in the intermediate loading file to obtain the first loading result corresponding to the floor loading file until a first loading result indicating successful loading is obtained.
[0008] Optionally, obtaining the first loading result corresponding to the floor loading file using the intermediate loading file includes: determining the calling interface corresponding to the one or more floors respectively; and obtaining the first loading result corresponding to the floor loading file from the calling interface using the calling function.
[0009] Optionally, for the case where the second loading result is a loading failure, the method further includes: determining the calling interface corresponding to the one or more floors; obtaining the fourth loading result corresponding to the floor loading file from the calling interface using an alternative calling strategy; and generating the page based on the first loading result and the fourth loading result.
[0010] Optionally, the method further includes: obtaining a page template file of the page to be loaded; determining a second loading result of the page template file; and loading the page according to the second loading result and the first loading result if the second loading result indicates successful loading.
[0011] Optionally, before obtaining the first loading result corresponding to the floor loading file using the intermediate loading file, the method further includes: determining that the third loading result of the intermediate loading file is successfully loaded.
[0012] Optionally, the space occupied by the intermediate loading file is smaller than the space occupied by the floor loading file.
[0013] To achieve the above objectives, according to another aspect of the present invention, a page loading apparatus is provided.
[0014] An embodiment of the present invention provides a page loading apparatus comprising: an acquisition module, configured to acquire floor loading files and intermediate loading files corresponding to one or more floors included in the page to be loaded; an intermediate loading module, configured to acquire a first loading result corresponding to the floor loading file using the intermediate loading file; and a page loading module, configured to load the page according to the first loading result.
[0015] To achieve the above objectives, according to another aspect of the present invention, a page-loading electronic device is provided.
[0016] An electronic device for page loading according to an embodiment of the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a page loading method according to an embodiment of the present invention.
[0017] To achieve the above objectives, according to another aspect of the present invention, a computer-readable storage medium is provided.
[0018] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements a page loading method according to an embodiment of the present invention.
[0019] One embodiment of the above invention has the following advantages or beneficial effects: by setting an intermediate loading file corresponding to the floor, the intermediate loading file can be loaded first, and then the intermediate loading file can be used to obtain the loading result corresponding to the floor loading file, thereby solving the problem of loading failure caused by directly obtaining the loading result corresponding to the floor loading file from the page loading file.
[0020] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0021] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0022] Figure 1 This is a schematic diagram illustrating the main steps of a page loading method according to an embodiment of the present invention;
[0023] Figure 2 This is a schematic diagram of the main steps of another page loading method according to an embodiment of the present invention;
[0024] Figure 3 This is a schematic diagram of the main steps for obtaining the first loading result according to an embodiment of the present invention;
[0025] Figure 4 This is a schematic diagram of the execution order enumeration according to an embodiment of the present invention;
[0026] Figure 5 This is a schematic diagram of the main steps in the case where the second loading result is a loading failure according to an embodiment of the present invention;
[0027] Figure 6 This is a schematic diagram of the main modules of a page loading apparatus according to an embodiment of the present invention;
[0028] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0029] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0030] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0031] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.
[0032] Figure 1 This is a schematic diagram illustrating the main steps of a page loading method according to an embodiment of the present invention.
[0033] like Figure 1 As shown, the page loading method of this invention mainly includes the following steps:
[0034] Step S101: Obtain the floor loading files and intermediate loading files corresponding to one or more floors included in the page to be loaded;
[0035] Step S102: Use the intermediate loading file to obtain the first loading result corresponding to the floor loading file;
[0036] Step S103: Load the page based on the first loading result.
[0037] For a page to be loaded, it is usually necessary to load the page template and the floor separately in order to display one or more floors in the page template. In the existing technology, the first loading result of each floor is called by calling the interface only when the page template is loaded. If the floor has not been loaded successfully at this time, that is, if the first loading result indicates that the loading has failed, then the page will fail to load.
[0038] The first loading result indicates whether the floor loading file was loaded successfully. In this embodiment, the intermediate loading file is the loading entry point corresponding to the floor loading file, and the floor loading file is the business code for a specific floor. To implement step S102, in an optional embodiment, the space occupied by the intermediate loading file is smaller than that of the floor loading file; that is, the intermediate loading file can be loaded first, ensuring the loading order between the intermediate and floor loading files. Typically, the space occupied by the intermediate loading file is less than 1kb. In a further optional embodiment, before step S102, a third loading result of the intermediate loading file is determined to be successful. Only if the intermediate loading file is successfully loaded can the first result of the floor loading file be called using the calling function in the intermediate loading file.
[0039] In an optional embodiment, the page loading method of this invention is as follows: Figure 2 As shown, it also includes:
[0040] Step S201: Obtain the page template file of the page to be loaded;
[0041] Step S202: Determine the second loading result of the page template file;
[0042] Step S203: If the second loading result is successful, load the page based on the second loading result and the first loading result.
[0043] During the loading process, the browser can execute each loaded file synchronously or asynchronously. That is, the loading processes of intermediate loaded files, page template files, and floor loaded files are independent of each other. The browser can obtain the second loading result corresponding to the page template file, the third loading result corresponding to the intermediate loaded file, and the first loading result corresponding to the floor loaded file, respectively. However, if the page template file wants to know the third loading result corresponding to the intermediate loaded file, it needs to assign a value in its function call. Similarly, it needs to assign a value in the function call of the intermediate loaded file to obtain the first loading result corresponding to the floor loaded file. Therefore, in an optional embodiment, step S102 can be as follows: Figure 3 As shown, it further includes:
[0044] Step S301: Determine the calling interface corresponding to one or more floors;
[0045] Step S302: Use the calling function to obtain the first loading result corresponding to the floor loading file from the calling interface.
[0046] For the first loading result, loading failure may occur. In order to solve the problem that the loading failure caused by the interface being called only once during the page loading process in the prior art cannot be improved, in an optional embodiment, it is further included: if the first loading result is loading failure, after a preset time period, the calling function in the intermediate loading file is reused to obtain the first loading result corresponding to the floor loading file until the first loading result indicating successful loading is obtained.
[0047] By obtaining the first loading result of the floor loading file multiple times, the effect of waiting for the floor loading file to load smoothly can be achieved, without the situation where the slow loading is due to the floor loading file being too large and thus being identified as a loading failure, effectively solving the problem of loading anomalies.
[0048] The following is based on Figure 4Taking an example, this invention's embodiment specifically illustrates how the method reduces the probability of loading exceptions. In one optional embodiment, all loading files are JS (JavaScript) files. The page template file is `main.js`, and the functions called in the page template are all `window._JDT_NYF.init()`. The floor loading file is `app.js`, and the intermediate loading file is `jssdk.js`. Since the intermediate loading file occupies much less space than the floor loading file, it must be loaded before the floor loading file. Furthermore, each loading file is loaded synchronously or asynchronously. Therefore, it's possible for the page template file to load first (various scenarios in Scheme Two), or for the intermediate loading file to load first (various scenarios in Scheme One). Typically, JS files contain `<script>` tags, which include the `defer` and `async` attributes. When the `async` attribute is set, it indicates that the document loading and rendering are parallel to the JS script loading and execution (synchronous execution). When the `defer` attribute is set, it indicates that the document loading and rendering process and the JS script loading process are asynchronous. As can be seen from the enumeration, page loading will only fail in the last case of Scheme 2, where the intermediate loading file has not yet finished loading when the loading result of the intermediate loading file is called using the calling method. However, since the intermediate loading file occupies very little space, the probability that the intermediate loading file jssdk.js has not finished loading after the page template file has been loaded is extremely low. In other words, with the page loading method provided by this invention, the probability of page loading failure is extremely low regardless of whether the script tag in the js file is set to synchronous or asynchronous execution.
[0049] In an optional embodiment, when the intermediate loading file fails to load, that is, when the second loading result is a loading failure, such as Figure 5 As shown, it also includes:
[0050] Step S501: Determine the calling interface corresponding to one or more floors;
[0051] Step S502: Use the alternative calling strategy to obtain the fourth loading result corresponding to the floor loading file from the calling interface;
[0052] Step S503: Generate the page based on the first loading result and the fourth loading result.
[0053] Although the failure to load intermediate files is a low-probability event, there are still cases where intermediate files are corrupted or the code is miswritten, which can lead to failure to load successfully. In this case, it is no longer possible to call the third loading result corresponding to the floor loading file through the intermediate loading file. It is necessary to use more complex code to write an alternative calling strategy to ensure that the page template file can directly obtain the loading result corresponding to the floor loading file through the calling interface via a new calling function.
[0054] As can be seen from the page loading method according to embodiments of the present invention, by setting a small intermediate loading file corresponding to each floor, the intermediate loading file can be loaded first, and then the loading result corresponding to the floor loading file can be obtained using the intermediate loading file. This solves the problem of loading failure caused by the page loading file directly obtaining the loading result corresponding to the floor loading file. Furthermore, the intermediate loading file can repeatedly call the loading result corresponding to the floor loading file, greatly reducing the probability of page loading failure.
[0055] Figure 6 This is a schematic diagram of the main modules of a page loading apparatus according to an embodiment of the present invention.
[0056] like Figure 6 As shown, the page loading apparatus 600 of this embodiment includes:
[0057] The acquisition module 601 is used to acquire the floor loading files and intermediate loading files corresponding to one or more floors included in the page to be loaded;
[0058] Intermediate loading module 602 is used to obtain the first loading result corresponding to the floor loading file using the intermediate loading file;
[0059] Page loading module 603 is used to load a page based on the first loading result.
[0060] In an optional embodiment of the present invention, the intermediate loading module 602 is further configured to, in the case that the first loading result is a loading failure, re-use the calling function in the intermediate loading file to obtain the first loading result corresponding to the floor loading file after a preset time period, until a first loading result indicating successful loading is obtained.
[0061] In an optional embodiment of the present invention, the intermediate loading module 602 is further configured to determine the calling interface corresponding to the one or more floors respectively; and use the calling function to obtain the first loading result corresponding to the floor loading file from the calling interface.
[0062] In an optional embodiment of the present invention, the page loading module 603 is further configured to: determine the calling interface corresponding to the one or more floors in the case that the second loading result is a loading failure; obtain the fourth loading result corresponding to the floor loading file from the calling interface using a backup calling strategy; and generate the page based on the first loading result and the fourth loading result.
[0063] In an optional embodiment of the present invention, the acquisition module 601 is further configured to acquire a page template file of the page to be loaded; the page loading module 603 is further configured to determine a second loading result of the page template file; and if the second loading result is successful, load the page according to the second loading result and the first loading result.
[0064] In an optional embodiment of the present invention, the intermediate loading module 602 is further configured to determine that the third loading result of the intermediate loading file is successfully loaded before obtaining the first loading result corresponding to the floor loading file using the intermediate loading file.
[0065] In an optional embodiment of the present invention, the space occupied by the intermediate loading file is smaller than the space occupied by the floor loading file.
[0066] As can be seen from the page loading apparatus according to embodiments of the present invention, by setting a small intermediate loading file corresponding to each floor, the intermediate loading file can be loaded first, and then the loading result corresponding to the floor loading file can be obtained using the intermediate loading file. This solves the problem of loading failure caused by directly obtaining the loading result corresponding to the floor loading file from the page loading file. Furthermore, the intermediate loading file can repeatedly call the loading result corresponding to the floor loading file, greatly reducing the probability of page loading failure.
[0067] Figure 7 An exemplary system architecture 700 is shown, in which the page loading method or apparatus of embodiments of the present invention can be applied.
[0068] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, a network 704, and a server 705. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0069] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send data. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, and social media platforms.
[0070] Terminal devices 701, 702, and 703 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0071] Server 705 can be a server that provides various services, such as a backend management server that supports the pages browsed by users using terminal devices 701, 702, and 703. The backend management server can analyze and process data such as received page loading requests, and feed back the processing results (such as page loading results) to the terminal devices.
[0072] It should be understood that Figure 7 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0073] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing a terminal device of the present invention. Figure 8 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0074] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) first interface 805 is also connected to the bus 804.
[0075] The following components are connected to the I / O first interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network first interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O first interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 810 as needed so that computer programs read from it can be installed into the storage section 808 as needed.
[0076] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.
[0077] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0078] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0079] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including an acquisition module, an intermediate loading module, and a page loading module. The names of these modules do not necessarily limit the module itself; for example, the acquisition module can also be described as "a module for acquiring floor loading files and intermediate loading files corresponding to one or more floors included in the page to be loaded."
[0080] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: obtaining floor loading files and intermediate loading files corresponding to one or more floors included in a page to be loaded; obtaining a first loading result corresponding to the floor loading file using the intermediate loading file; and loading the page according to the first loading result.
[0081] According to the technical solution of the present invention, by setting an intermediate loading file corresponding to the floor, the intermediate loading file can be loaded first, and then the loading result corresponding to the floor loading file can be obtained by using the intermediate loading file, thereby solving the problem of loading failure caused by directly obtaining the loading result corresponding to the floor loading file from the page loading file.
[0082] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for loading a page, characterized in that, include: Obtain the floor loading files and intermediate loading files corresponding to one or more floors of the page to be loaded; wherein, the intermediate loading file is the loading entry point corresponding to the floor loading file, and the space occupied by the intermediate loading file is less than the space occupied by the floor loading file; If the third loading result of the intermediate loading file is determined to be successful, the first loading result corresponding to the floor loading file is obtained by using the function call in the intermediate loading file; the first loading result indicates whether the floor loading file was loaded successfully. The page is loaded based on the first loading result.
2. The method according to claim 1, characterized in that, Also includes: If the first loading result is a loading failure, the first loading result corresponding to the floor loading file is obtained again by reusing the calling function in the intermediate loading file after a preset time period, until a first loading result indicating successful loading is obtained.
3. The method according to claim 2, characterized in that, The step of obtaining the first loading result corresponding to the floor loading file by using the function call in the intermediate loading file includes: Determine the calling interface corresponding to each of the one or more floors; The first loading result corresponding to the floor loading file is obtained from the calling interface using the calling function.
4. The method according to claim 1, characterized in that, For the case where the third loading result is loading failure, the following also applies: Determine the calling interface corresponding to the one or more floors; The fourth loading result corresponding to the floor loading file is obtained from the calling interface using the alternative calling strategy; The page is generated based on the first loading result and the fourth loading result.
5. The method according to claim 1, characterized in that, Also includes: Get the page template file of the page to be loaded; Determine the second loading result of the page template file; If the second loading result indicates successful loading, the page is loaded based on the second loading result and the first loading result.
6. A page loading apparatus, characterized in that, include: The acquisition module is used to acquire the floor loading files and intermediate loading files corresponding to one or more floors included in the page to be loaded; wherein, the intermediate loading file is the loading entry corresponding to the floor loading file, and the space occupied by the intermediate loading file is smaller than the space occupied by the floor loading file; The intermediate loading module is used to determine that the third loading result of the intermediate loading file is successful, and to obtain the first loading result corresponding to the floor loading file by using the calling function in the intermediate loading file; the first loading result is an indication of whether the floor loading file has been loaded successfully. The page loading module is used to load the page based on the first loading result.
7. An electronic device for data processing, characterized in that, include: One or more processors; 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 as described in any one of claims 1-5.
8. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.