CN-122019899-A - Offline package generation method, webpage rendering method, electronic equipment and medium
Abstract
The application relates to the technical field of computers, and discloses a method for generating an offline package, a method for rendering a webpage, electronic equipment and a medium. The method comprises the steps of obtaining a static resource file of a target webpage to be rendered and a uniform resource locator corresponding to the static resource file, wherein the static resource file is constructed by a construction server based on a source code file corresponding to the target webpage, pre-accessing the target webpage based on the uniform resource locator to generate a main static resource corresponding to the target webpage, and compressing the main static resource to generate a main offline package corresponding to the target webpage. By implementing the method of the application, the situations that the offline package is too large and contains unnecessary static resources and the offline package is too small and lacks the static resources required by the Web page for displaying the first screen can be avoided, thereby solving the problem of longer loading time of the Web page.
Inventors
- LIN XIAOLEI
- WU PENG
- Pan Xiandiao
- CHEN JINHAI
- CHEN MIAORONG
Assignees
- 杭州网易云音乐科技有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20251215
Claims (18)
- 1. A method for generating an offline package, the method comprising: Acquiring a static resource file of a target webpage to be rendered and a uniform resource locator corresponding to the static resource file, wherein the static resource file is constructed by a construction server based on a source code file corresponding to the target webpage; Pre-accessing the target webpage based on the uniform resource locator to generate a main static resource corresponding to the target webpage; and compressing the main static resource to generate a main offline package corresponding to the target webpage.
- 2. The method of claim 1, wherein the pre-accessing the target web page based on the uniform resource locator to generate the main static resource corresponding to the target web page comprises: Loading the target webpage in response to an operation of inputting the uniform resource locator into a target browser; Inquiring a target style resource file and a target interaction resource file required by preloading the target webpage from the static resource file in the process of loading the target webpage; Acquiring style resource information aiming at the target webpage from the target style resource file; Based on interface information in the target interaction resource file, acquiring interaction resource information aiming at the target webpage; And fusing the target style resource file, the target interactive resource file, the style resource information and the interactive resource information to obtain the main static resource.
- 3. The method according to claim 2, wherein the obtaining the interaction resource information for the target web page based on the interface information in the target interaction resource file includes: Generating an access request for accessing the content distribution server based on the interface information in the target interaction resource file; Pushing the access request to the content distribution server; and receiving the interactive resource information which is pushed by the content distribution server and aims at the access request.
- 4. A method according to any one of claims 1 to 3, characterized in that the method further comprises: Pushing the main offline package to a content distribution server so that the content distribution server generates a main download link corresponding to the main offline package; generating first configuration information based on the main download link pushed by the content distribution server, pushing the first configuration information to a configuration server, and downloading the main offline package by the first configuration information.
- 5. A method according to any one of claims 1 to 3, characterized in that the method further comprises: compressing other static resources except the main static resource in the static resource file to generate a sub offline package corresponding to the target webpage; Pushing the sub-offline package to a content distribution server so that the content distribution server generates a sub-download link corresponding to the sub-offline package; Generating second configuration information based on the sub-download link pushed by the content distribution server, and pushing the second configuration information to a configuration server, wherein the second configuration information is used for downloading the sub-offline package.
- 6. A method according to any one of claims 1 to 3, characterized in that the method further comprises: acquiring a current anchor point version number, a new offline package and a latest version number of the new offline package; Determining whether the latest version number of the new offline packet is the latest anchor point version number or not based on a fusion result of a preset version number interval and the current anchor point version number; If the latest version number is the latest anchor point version number, determining a first difference packet between the new offline packet and the historical anchor point offline packets corresponding to the historical anchor point version numbers and a second difference packet between the new offline packet and the current anchor point offline packet corresponding to the current anchor point version number; If the latest version number is not the latest anchor point version number, determining a third delta packet between the new offline packet and the current anchor point offline packet; The historical anchor offline package, the current anchor offline package and the new offline package are the same in package type.
- 7. The method of claim 6, wherein the method further comprises: Pushing the first delta packet and the second delta packet to a content distribution server, so that the content distribution server generates a first download link corresponding to the first delta packet and a second download link corresponding to the second delta packet; constructing a first mapping relation based on a first delta version number of the first delta packet and the first download link pushed by the content distribution server, pushing the first mapping relation to a configuration server, so that the configuration server generates a first configuration file based on the first mapping relation and sends the first configuration file to a client; And constructing a second mapping relation based on a second delta version number of the second delta packet and the second download link pushed by the content distribution server, pushing the second mapping relation to the configuration server, so that the configuration server generates a second configuration file based on the second mapping relation and sends the second configuration file to a client.
- 8. The method of claim 6, wherein the method further comprises: Pushing the third delta packet to a content distribution server so that the content distribution server generates a third download link corresponding to the third delta packet; constructing a third mapping relation based on a third delta version number of the third delta packet and a third download link pushed by the content distribution server; Pushing the third mapping relation to a configuration server, so that the configuration server generates a third configuration file based on the third mapping relation and sends the third configuration file to a client.
- 9. A method for rendering a web page, the method comprising: Responding to the starting operation of a client, acquiring a main offline package corresponding to a target webpage, wherein the main offline package is obtained by compressing main static resources, the main static resources are generated by pre-accessing the target webpage based on uniform resource locators corresponding to static resource files, and the static resource files are constructed by a construction server based on source code files corresponding to the target webpage; And rendering the target webpage based on the main static resource corresponding to the main offline package.
- 10. The method of claim 9, wherein the obtaining the main offline package corresponding to the target web page includes: Responding to request operation of configuration information of the target webpage, and acquiring first configuration information corresponding to the target webpage from a configuration server; And accessing a content distribution server based on a main download link carried by the first configuration information, and downloading the main offline package corresponding to the main download link from the content distribution server.
- 11. The method according to claim 9, wherein the method further comprises: responding to the triggering operation aiming at the target webpage, and acquiring second configuration information corresponding to the target webpage from a configuration server; Accessing a content distribution server based on the sub-download link carried by the second configuration information, and downloading a sub-offline package from the content distribution server; and rendering the target webpage based on other static resources corresponding to the sub offline package.
- 12. The method according to any one of claims 9 to 11, characterized in that the method further comprises: Receiving the latest version number of the new offline package pushed by the configuration server and a second configuration file; determining whether a version number of a local offline packet is a current anchor point version number and whether the latest version number is a latest anchor point version number; If the version number of the local offline packet is the current anchor point version number and the latest version number is the latest anchor point version number, a second download link corresponding to a second delta packet is queried from a second configuration file; downloading the second delta package from a content distribution server based on the second download link; updating the local offline package to the new offline package based on a fusion result of the local offline package and the second delta package; the second configuration file is configured to store a second download link corresponding to a second delta packet, where the second delta packet is a delta packet between the new offline packet and the current anchor offline packet corresponding to the current anchor version number, and the local offline packet, the current anchor offline packet, and the new offline packet are the same in packet type.
- 13. The method according to claim 12, wherein the method further comprises: receiving a third configuration file pushed by the configuration server; If the version number of the local offline packet is the current anchor point version number and the latest version number is not the latest anchor point version number, a third download link corresponding to a third delta packet is queried from the third configuration file; Downloading the third delta package from the content distribution server based on the third download link; updating the local offline package to the new offline package based on a fusion result of the local offline package and the third delta package; The third configuration file is configured to store a third download link corresponding to the third delta packet, where the third delta packet is a delta packet between the new offline packet and the current anchor offline packet corresponding to the current anchor version number, and the local offline packet, the current anchor offline packet, and the new offline packet are the same in packet type.
- 14. The method according to claim 12, wherein the method further comprises: receiving a first configuration file pushed by the configuration server; if the version number of the local offline package is a historical anchor point version number and the latest version number is the latest anchor point version number, inquiring a first download link corresponding to a first delta package from the first configuration file; downloading the first delta package from the content distribution server based on the first download link; Updating the local offline package to the new offline package based on a fusion result of the local offline package and the first delta package; The first configuration file is used for storing a first download link corresponding to the first delta packet, the first delta packet is a delta packet between the new offline packet and a history anchor offline packet corresponding to the history anchor version number, and the local offline packet, the history anchor offline packet and the new offline packet are the same in packet type.
- 15. The method of claim 13, wherein the method further comprises: Receiving a fourth configuration file pushed by the configuration server, If the version number of the local offline package is a historical anchor point version number and the latest version number is not the latest anchor point version number, a fourth download link corresponding to a fourth delta package is queried from the fourth configuration file; downloading the fourth delta package from the content distribution server based on the fourth download link; Updating the local offline package to the new offline package based on a fusion result among the local offline package, the fourth delta package and the third delta package; the fourth configuration file is configured to store a fourth download link of the fourth delta packet, where the fourth delta packet is a delta packet between the current anchor offline packet and the history anchor offline packet corresponding to the history anchor version number.
- 16. The method of claim 13, wherein the method further comprises: if the version number of the local offline package is not the anchor point version number and the latest version number is not the latest anchor point version number, a fifth download link corresponding to the current anchor point offline package is obtained from the configuration server; Downloading the current anchor offline package from the content distribution server based on the fifth download link; And updating the local offline package to the new offline package based on the fusion result of the current anchor offline package and the third delta package, wherein the package types of the current anchor offline package and the new offline package are the same.
- 17. An electronic device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory having stored therein computer instructions, the processor executing the computer instructions to perform the method of generating an offline package according to any one of claims 1 to 8, or the method of rendering a web page according to any one of claims 9 to 16.
- 18. A computer-readable storage medium having stored thereon computer instructions for causing a computer to perform the method of generating an offline package according to any one of claims 1 to 8 or the method of rendering a web page according to any one of claims 9 to 16.
Description
Offline package generation method, webpage rendering method, electronic equipment and medium Technical Field The invention relates to the technical field of computers, in particular to a generation method of an offline package, a rendering method of a webpage, electronic equipment and a medium. Background With the development of mobile internet technology, the hybrid application program (Hybrid Application) becomes a mainstream development mode of mobile application because of the advantages of good user experience of the native application and efficient development of the Web development platform. However, the loading of the Web page in the hybrid application program is seriously dependent on the network environment, and static resources required by the Web page, such as an interaction script file (JavaScript file), a style resource file (CSS file), pictures, text and the like, need to be acquired from a server in real time through a network request, so that the loading speed of the Web page is slow and the rendering time is long due to the influence of factors such as network delay, bandwidth fluctuation and the like. Based on this, static resources required for running Web pages are typically split and packaged into a plurality of offline packages, which are then integrated into the installation package of the hybrid application or downloaded to the user device in advance via the network and stored locally. At present, static resources required for running a Web page are split and packaged based on experience pre-judgment and static analysis of developers, so that the situation that an offline package is too large and contains unnecessary static resources is easy to occur, and the offline package is too small and lacks the static resources required for displaying the Web page of a first screen, thereby leading to longer loading time of the Web page and poorer use experience of users. Disclosure of Invention The invention provides a method for generating an offline package, a method for rendering a webpage, electronic equipment and a medium, which are used for solving the problem of longer loading time of the webpage. The method comprises the steps of obtaining a static resource file of a target webpage to be rendered and a uniform resource locator corresponding to the static resource file, wherein the static resource file is constructed by a construction server based on a source code file corresponding to the target webpage, pre-accessing the target webpage based on the uniform resource locator to generate a main static resource corresponding to the target webpage, compressing the main static resource, and generating a main offline package corresponding to the target webpage. In a second aspect, the invention provides a webpage rendering method, which comprises the steps of responding to a starting operation of a client to obtain a main offline package corresponding to a target webpage, wherein the main offline package is obtained by compressing main static resources, the main static resources are generated by pre-accessing the target webpage based on uniform resource locators corresponding to static resource files, the static resource files are built based on source code files corresponding to the target webpage by a building server, and the target webpage is rendered based on the main static resources corresponding to the main offline package. In a third aspect, the present invention provides an electronic device, including a memory and a processor, where the memory and the processor are communicatively connected to each other, and the memory stores computer instructions, and the processor executes the computer instructions, thereby executing the method for generating an offline package according to the first aspect or any implementation manner corresponding to the first aspect, or the method for rendering a web page according to the second aspect or any implementation manner corresponding to the second aspect. In a fourth aspect, the present invention provides a computer-readable storage medium having stored thereon computer instructions for causing a computer to execute the method for generating an offline package according to the first aspect or any of the embodiments corresponding thereto, or the method for rendering a web page according to the second aspect or any of the embodiments corresponding thereto. According to the offline package generation method, the target webpage is pre-accessed based on the uniform resource locator corresponding to the static resource file, so that the actual resource loading condition of the target webpage in the real user environment can be accurately obtained, and the main static resource required by the first screen for displaying the target webpage when the user accesses the target webpage can be accurately determined. The main offline package is obtained by compressing the main static resources, so that differential packaging is performed on static resource file