HTML (Hypertext Markup Language) file generation method and device, webpage access method and device, electronic equipment and medium
By using placeholder tags in HTML source files to mark the expected locations of static resources and replacing them with resource loading codes, the problem of random location of resource loading codes generated by front-end build tools is solved, improving web page performance and user experience.
Patent Information
- Application Number
- CN202410609733.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-08-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When building the HTML file of the web page entrance, the resource loading code of the static resources generated using front-end construction tools such as Webpack and Vite is in random positions, which affects web page performance and user experience.
By obtaining the HTML source file containing placeholder tags, using the preset front-end build tool to generate the initial HTML file, and replacing the placeholder tags with the resource loading code of the static resource, ensure that the resource loading code is located at the desired location.
Improved web page performance, shortened the first content rendering time, optimized user experience, and avoided static resource blocking and preemption caused by random resource loading code locations.
Smart Images

Figure CN118567743A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an HTML file generation method, a web page access method, a device, an electronic device and a medium. Background Art
[0002] In front-end projects, when building HTML (Hypertext Markup Language) files for web page entrances, front-end building tools such as Webpack and Vite are usually used to generate resource loading codes for static resources. However, this method will affect the performance of the web page due to the random generation location of the resource loading code, thereby affecting the user experience of accessing the web page. Summary of the invention
[0003] In view of this, an object of the present invention is to provide an HTML file generation method, a web page access method, a device, an electronic device and a medium to improve web page performance and optimize user experience.
[0004] In order to achieve the above object, the technical solution adopted by the present invention is as follows:
[0005] In view of this, an object of the present invention is to provide an HTML file generating method, a web page accessing method, an HTML file generating device, a web page accessing device, an electronic device and a storage medium.
[0006] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows:
[0007] In a first aspect, the present invention provides a method for generating an HTML file, the method comprising:
[0008] Obtaining an HTML source file of a web page entrance; the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource;
[0009] Generate an initial HTML file based on the HTML source file using a preset front-end building tool; the initial HTML file includes a resource loading code for each static resource;
[0010] Each placeholder tag in the initial HTML file is replaced with a resource loading code of a corresponding static resource to obtain a target HTML file for a web page entrance.
[0011] In an optional implementation manner, the position of each placeholder tag in the HTML source file is located after the position of the web page frame preview code.
[0012] In an optional implementation, the step of replacing each placeholder tag in the initial HTML file with a resource loading code of a corresponding static resource to obtain a target HTML file of a web page entrance includes:
[0013] According to each of the placeholder tags and each of the resource loading codes in the initial HTML file, a resource mapping relationship between each of the placeholder tags and the resource loading codes matched thereto is obtained;
[0014] According to the resource mapping relationship, each placeholder tag in the initial HTML file is replaced with its matching resource loading code to obtain the target HTML file of the webpage entrance.
[0015] In an optional implementation, the placeholder tag includes a resource identifier representing a static resource;
[0016] The step of obtaining a resource mapping relationship between each placeholder tag and the resource loading code matched thereto according to each placeholder tag and each resource loading code in the initial HTML file comprises:
[0017] Using a preset regular expression, identifying each of the placeholder tags in the initial HTML file, and obtaining a resource identifier of each of the placeholder tags;
[0018] For each placeholder tag, the resource loading code containing the resource identifier of the placeholder tag is extracted from the initial HTML file, the resource loading code matched by the placeholder tag is obtained, and a resource mapping relationship between each placeholder tag and the resource loading code matched thereto is obtained.
[0019] In a second aspect, the present invention provides a web page access method, the web page access method comprising:
[0020] According to the access instruction of the target webpage, an HTML file of the entrance of the target webpage is obtained; the resource loading code of each static resource in the HTML file is located after the webpage frame preview code;
[0021] Executing the webpage frame preview code in the HTML file to display the frame structure of the target webpage;
[0022] Execute the resource loading code of each static resource in the HTML file to load each static resource of the target web page;
[0023] The HTML file is obtained according to the HTML file generation method described in any one of the aforementioned implementations.
[0024] In a third aspect, the present invention provides an HTML file generating device, the HTML file generating device comprising:
[0025] An acquisition module is used to acquire an HTML source file of a web page entrance; the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource;
[0026] A generation module, used to generate an initial HTML file based on the HTML source file using a preset front-end building tool; the initial HTML file includes a resource loading code for each static resource;
[0027] The replacement module is used to replace each placeholder tag in the initial HTML file with the resource loading code of the corresponding static resource to obtain the target HTML file of the web page entrance.
[0028] In an optional embodiment, the replacement module is further used for:
[0029] According to each of the placeholder tags and each of the resource loading codes in the initial HTML file, a resource mapping relationship between each of the placeholder tags and the resource loading codes matched thereto is obtained;
[0030] According to the resource mapping relationship, each placeholder tag in the initial HTML file is replaced with its matching resource loading code to obtain the target HTML file of the webpage entrance.
[0031] In a fourth aspect, the present invention provides a web page access device, the web page access device comprising:
[0032] The access module is used to obtain the HTML file of the target web page entrance according to the access instruction of the target web page; the resource loading code of each static resource in the HTML file is located after the web page frame preview code;
[0033] An execution module, used for executing the web page frame preview code in the HTML file to display the frame structure of the target web page;
[0034] Execute the resource loading code of each static resource in the HTML file to load each static resource of the target web page;
[0035] The HTML file is obtained according to the HTML file generation method described in any one of the aforementioned implementations.
[0036] In a fifth aspect, the present invention provides an electronic device, comprising a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the HTML file generation method described in any one of the aforementioned embodiments, and / or the web page access method described in the aforementioned embodiments.
[0037] In a sixth aspect, the present invention provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the HTML file generation method described in any one of the aforementioned embodiments, and / or the web page access method described in the aforementioned embodiments.
[0038] The HTML file generation method, web page access method, device, electronic device and medium provided by the present invention include: firstly obtaining the HTML source file of the web page entrance, the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the static resource corresponding to it; then using a preset front-end construction tool to generate an initial HTML file based on the HTML source file, the initial HTML file includes the resource loading code of each static resource; finally, each placeholder tag in the initial HTML file is replaced with the resource loading code of the static resource corresponding to it, so as to obtain the target HTML file of the web page entrance. By using placeholder tags to mark the expected position of static resources, and replacing the placeholder tags with the resource loading code of static resources, the resource loading code of each static resource in the HTML file is located at the expected position, so as to avoid the random position of the resource loading code affecting the web page performance, thereby improving the web page performance and optimizing the user experience.
[0039] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0041] Figure 1 A block diagram of an electronic device provided by an embodiment of the present invention is shown;
[0042] Figure 2 A schematic diagram showing a flow chart of a method for generating an HTML file provided by an embodiment of the present invention;
[0043] Figure 3A schematic diagram showing a flow chart of a web page access method provided by an embodiment of the present invention;
[0044] Figure 4 A functional module diagram of an HTML file generating device provided by an embodiment of the present invention is shown;
[0045] Figure 5 A functional module diagram of a web page access device provided by an embodiment of the present invention is shown.
[0046] Icons: 100 - electronic device; 110 - bus; 120 - processor; 130 - memory; 150 - I / O module; 170 - communication module; 300 - HTML file generating device; 310 - acquisition module; 330 - generating module; 350 - replacing module; 400 - web page accessing device; 410 - access module; 430 - execution module. DETAILED DESCRIPTION
[0047] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0048] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0049] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0050] In front-end projects, when constructing HTML (Hyper Text Markup Language) files for web page entrances, front-end construction tools such as Webpack and Vite are usually used to generate resource loading codes for static resources. However, this method will affect the performance of the web page due to the random generation location of the resource loading code. For example, if the generation location of the resource loading code is inappropriate, such as in the Head tag or in a location that the developer does not want to place it, it will cause static resources to block or preempt the loading of the web page, which will cause the FCP (First Contentful Paint) time of the web page to be long, so the time for the user to display a white screen when accessing the web page will be longer, that is, the user needs to wait for a long time before the web page displays the content, thereby affecting the user experience. Therefore, an embodiment of the present invention provides an HTML file generation method.
[0051] Please refer to Figure 1 , is a block diagram of an electronic device provided by an embodiment of the present invention. The electronic device 100 includes a bus 110 , a processor 120 , a memory 130 , an I / O module 150 , and a communication module 170 .
[0052] The bus 110 may be a circuit that connects the above-mentioned elements to each other and transfers signals between the elements.
[0053] The processor 120 may receive commands from the other elements described above (eg, the memory 130 , the I / O module 150 , the communication module 170 , etc.) through the bus 110 , may interpret the received commands, and may perform calculations or data processing according to the interpreted commands.
[0054] The processor 120 may be an integrated circuit chip with signal processing capabilities. The processor 120 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0055] The memory 130 may store commands or data received from the processor 120 or other elements (eg, the I / O module 150 , the communication module 170 , etc.) or commands or data generated by the processor 120 or other elements.
[0056] The memory 130 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), or an electrically erasable programmable read-only memory (EEPROM).
[0057] The I / O module 150 may receive commands or data input from a user via input-output means (e.g., a sensor, a keyboard, a touch screen, etc.), and may transmit the received commands or data to the processor 120 or the memory 130 via the bus 110. It is also used to display various information (e.g., multimedia data, text data) received, stored, and processed from the above elements, and may display videos, images, data, etc. to the user.
[0058] The communication module 170 may be used to communicate signals or data with other devices.
[0059] Understandably, Figure 1 The structure shown is only a schematic diagram of the structure of the electronic device 100. The electronic device 100 may also include Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown. Figure 1 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0060] The electronic device provided in the embodiment of the present invention may be a personal computer, a tablet computer, a netbook, a personal digital assistant, etc. The embodiment of the present invention does not impose any limitation on this.
[0061] The above-mentioned electronic device 100 will be used as an execution subject to execute each step in each method provided in the embodiment of the present invention and achieve corresponding technical effects.
[0062] See also Figure 2 , is a flow chart of the HTML file generation method provided by an embodiment of the present invention.
[0063] Step S202, obtaining the HTML source file of the web page entrance; the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource.
[0064] In this embodiment, the static resources may be CSS (Cascading Style Sheets) format files, preloaded JS (Java Script, scripting language) format files, and module JS format files. Among them, CSS format files are used to render the style of web pages, JS format files are used to implement the interaction of web pages, and CSS format files and preloaded JS format files are static resources that are loaded immediately, and module JS format files are static resources that need to be downloaded before they can be loaded.
[0065] When generating the HTML source file of the web page entrance, based on the multiple static resources that need to be loaded, placeholder tags corresponding to the multiple static resources can be inserted into the HTML source file, and the position of each placeholder tag in the HTML source file is the expected position of the corresponding static resource, that is, the HTML source file of the web page entrance is obtained. Among them, the expected position of the static resource can be understood as the position where the resource loading code of the expected static resource is set.
[0066] Step S204, using a preset front-end building tool to generate an initial HTML file based on the HTML source file; the initial HTML file includes a resource loading code for each static resource.
[0067] In this embodiment, based on the obtained HTML source file, the HTML source file can be compiled using a preset front-end building tool such as Webpack or Vite to generate a resource loading code for each static resource, that is, to obtain an initial HTML file, and the resource loading code for each static resource in the initial HTML file is not located in the expected position.
[0068] Step S206: Replace each placeholder tag in the initial HTML file with the resource loading code of the corresponding static resource to obtain the target HTML file of the web page entrance.
[0069] In this embodiment, the initial HTML file contains the resource loading code of each static resource and the placeholder tag corresponding to each static resource. Then, the resource loading code of each static resource can be used to replace the corresponding placeholder tag so that the resource loading code of each static resource is located in the expected position, that is, the target HTML file of the web page entrance is obtained.
[0070] It can be understood that the embodiment of the present invention uses placeholder tags to mark the expected positions of static resources in the process of constructing the HTML file of the web page entrance, and replaces the placeholder tags with the resource loading codes of the static resources, so that the resource loading codes of each static resource in the HTML file are located at the expected position, avoiding the random location of the resource loading code and affecting the web page performance, thereby improving the web page performance and optimizing the user experience.
[0071] It can be seen that based on the above steps, first obtain the HTML source file of the web page entrance, the HTML source file includes multiple placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource; then use the preset front-end construction tool to generate an initial HTML file based on the HTML source file, the initial HTML file includes the resource loading code of each static resource; finally, replace each placeholder tag in the initial HTML file with the resource loading code of the corresponding static resource to obtain the target HTML file of the web page entrance. By using placeholder tags to mark the expected position of static resources, and replacing the placeholder tags with the resource loading code of static resources, the resource loading code of each static resource in the HTML file is located at the expected position, avoiding the random position of the resource loading code and affecting the web page performance, thereby improving the web page performance and optimizing the user experience.
[0072] Optionally, the position of each placeholder tag in the HTML source file is located after the position of the web page frame preview code.
[0073] In this embodiment, the HTML source file includes a web page frame preview code, which can be understood as a code for displaying a frame structure of a web page, such as a skeleton screen. Optionally, the HTML source file can also include a web page loading element, which can be understood as an icon or animation used to indicate that the web page is loading content, such as a progress bar, a rotating circle, etc.
[0074] It is understandable that the location of the code in the HTML file can reflect the execution order of the code. Since the front-end construction tools often generate the resource loading code of static resources into the Head tag or before the web page frame preview code and the web page loading element, when accessing the web page, the resource loading code of static resources will be executed first, which will preempt or block the loading of the web page content, resulting in a longer white screen time for the web page, and the user will have to wait for a long time before the web page displays the content, affecting the user experience.
[0075] Therefore, in the embodiment of the present invention, in the HTML source file, the position of each placeholder tag is set after the web page frame preview code and the web page loading element, and the web page frame preview code and the web page loading element are located after the Head tag, so that it can be ensured that in the HTML file of the final generated web page entry, the resource loading code of the static resource will not be in the Head tag, and will be located after the web page frame preview code and the web page loading element. In this way, when accessing a web page, the web page frame preview code and the web page loading element will be executed first, and the framework structure and loading elements of the web page can be displayed quickly, effectively preventing the slow loading of the web page content caused by loading static resources first, thereby shortening the FCP time of the web page, reducing the time of displaying a white screen, and improving the user experience of accessing the web page.
[0076] Optionally, for step S206, an embodiment of the present invention provides a possible implementation method.
[0077] Step S206 - 1 : obtaining a resource mapping relationship between each placeholder tag and the resource loading code matched thereto according to each placeholder tag and each resource loading code in the initial HTML file.
[0078] Step S206-3: According to the resource mapping relationship, each placeholder tag in the initial HTML file is replaced with its matching resource loading code to obtain the target HTML file of the web page entrance.
[0079] In this embodiment, according to each placeholder tag and each resource loading code in the initial HTML file, the resource loading code matched by each placeholder tag can be determined, and the matching relationship between the multiple placeholder tags and the multiple resource loading codes is obtained, that is, the resource mapping relationship is obtained. Then, according to the resource mapping relationship, each placeholder tag in the initial HTML file is replaced with the resource loading code matched thereto, and the target HTML file of the webpage entrance is obtained.
[0080] It can be understood that the embodiment of the present invention establishes a matching relationship between the resource loading code of the static resource and its corresponding placeholder tag based on the static resource, that is, obtains a resource mapping relationship, and replaces the placeholder tag with the resource loading code matching it based on the resource mapping relationship to ensure that the resource loading code is placed in the correct expected position, thereby improving the web page performance and optimizing the user experience.
[0081] Optionally, for step S206-1, an embodiment of the present invention provides a possible implementation method.
[0082] Step S206-1-1, using a preset regular expression, identifying each placeholder tag in the initial HTML file, and obtaining a resource identifier of each placeholder tag.
[0083] Step S206-1-3, for each placeholder tag, extract the resource loading code containing the resource identifier of the placeholder tag from the initial HTML file, obtain the resource loading code matched by the placeholder tag, and obtain the resource mapping relationship between each placeholder tag and the resource loading code matched thereto.
[0084] In this embodiment, the placeholder tag includes a set placeholder symbol and a resource identifier for representing a static resource. For example, the format of the placeholder tag can be expressed as: first placeholder symbol-resource identifier-second placeholder symbol, wherein the first placeholder symbol and the second placeholder symbol are the set placeholder symbols. The resource identifier includes the resource type and resource attributes of the static resource. For example, for static resources that are loaded instantly, such as CSS format files and preloaded JS format files, their resource type can be used for the first resource type symbol representation; for static resources that are not loaded instantly, such as module JS format files, their resource type can be used for the second resource type symbol representation.
[0085] For example, the first placeholder symbol can be set to <! --, the second placeholder symbol can be set to placeholder-->, the first resource type symbol can be set to link-rel, and the second resource type symbol can be set to script-type. It should be understood that the placeholder tag and resource identifier can also be set according to actual conditions, and the embodiment of the present invention is not limited to this.
[0086] For ease of understanding, an embodiment of the present invention provides an example. Assume that the initial HTML file includes three placeholder tags, namely: placeholder tag 1 <! --link-rel:stylesheet-placeholder-->, where stylesheet represents the resource attribute of the corresponding static resource; placeholder tag 2 <! --link-rel:modulepreload-placeholder-->, where modulepreload represents the resource attribute of the corresponding static resource; placeholder tag 3 <! --script-type:module-crossorigin-script-placeholder-->, where module-crossorigin-script represents the resource attribute of the corresponding static resource.
[0087] Based on the initial HTML file, a pre-set regular expression that matches the format of the placeholder tag can be used to identify each placeholder tag in the initial HTML file to obtain the resource identifier of each placeholder tag. For example, based on the format of the placeholder tag being the first placeholder symbol-resource identifier-second placeholder symbol, the format of the preset regular expression can be expressed as: a first identification symbol containing the first placeholder symbol-resource search symbol-a second identification symbol containing the second placeholder. For example, the format of the preset regular expression can be ( / <!--\s*(.*)-placeholder\s*--> / gim), where ( / <!--\ represents the first identification symbol, s*(.*) represents the resource search symbol, and placeholder\s*--> / gim) represents the second identification symbol.
[0088] Then, based on the resource identifier of each placeholder tag, the resource loading code containing the resource identifier of the placeholder tag can be extracted from the initial HTML file to obtain the resource loading code matched by the placeholder tag, and the resource loading code matched by each placeholder tag can be obtained, that is, the resource mapping relationship is obtained. Assume that the initial HTML file contains three resource loading codes, namely: Resource loading code 1 <link rel="stylesheet"crossorigin href="样式文件.css"> , Resource loading code 2 <link rel="modulepreload"crossorigin href="预加载js文件.js"> , Resource loading code 3 <script type="module"crossorigin src="模块js文件.js">< / script> .
[0089] Since resource loading code 1 contains the resource identifier of placeholder tag 1, namely link-rel-stylesheet, resource loading code 1 is the resource loading code matched by placeholder tag 1; since resource loading code 2 contains the resource identifier of placeholder tag 2, namely link-rel-modulepreload, resource loading code 2 is the resource loading code matched by placeholder tag 2; since resource loading code 3 contains the resource identifier of placeholder tag 3, namely script-type-module-crossorigin-script, resource loading code 3 is the resource loading code matched by placeholder tag 3; that is, the resource mapping relationship is obtained.
[0090] Optionally, for the HTML file generation method provided above, the embodiment of the present invention also provides a web page access method. Figure 3 , is a flow chart of a web page access method provided by an embodiment of the present invention.
[0091] Step S212, according to the access instruction of the target web page, obtain the HTML file of the target web page entrance; the resource loading code of each static resource in the HTML file is located after the web page frame preview code.
[0092] Step S214, executing the web page frame preview code in the HTML file to display the frame structure of the target web page.
[0093] Step S216, executing the resource loading code of each static resource in the HTML file to load each static resource of the target web page.
[0094] In this embodiment, according to the access instruction of the target web page, the HTML file of the target web page entrance is obtained, and the HTML file is obtained according to the above-mentioned HTML file generation method. Then, the resource loading code of each static resource in the HTML file is located after the web page frame preview code.
[0095] Then the codes in the HTML file are executed in sequence, that is, the webpage frame preview code is executed first, and the frame structure of the target webpage is displayed. Optionally, when there is a webpage loading element in the HTML file, the resource loading code of each static resource is located after the webpage loading element, and the loading element of the target webpage is also displayed to prompt the user that the webpage content is loading.
[0096] Then, the resource loading code of each static resource in the HTML file is executed in sequence, that is, each static resource of the target web page is loaded in sequence according to the position order of the resource loading code of each static resource in the HTML file.
[0097] It can be seen that the embodiment of the present invention sets the resource loading code of the static resources in the HTML file of the web page entrance after the web page frame preview code and the web page loading element. In this way, the web page frame preview code and the web page loading element will be executed first when the web page is accessed, and the framework structure and loading elements of the web page can be displayed quickly, which effectively prevents the slow loading of the web page content caused by loading the static resources first, thereby shortening the FCP time of the web page, reducing the time of displaying a white screen, and improving the user experience of accessing the web page.
[0098] In order to execute the corresponding steps of the HTML file generation method in the above embodiment, an implementation method of an HTML file generation device is provided below. Figure 4 , is a functional module diagram of an HTML file generating device provided in an embodiment of the present invention. It should be noted that the basic principle and technical effects of the HTML file generating device 300 provided in this embodiment are the same as those of the above embodiment. For the sake of brief description, for matters not mentioned in this embodiment, reference may be made to the corresponding contents in the above embodiment. The HTML file generating device 300 includes:
[0099] The acquisition module 310 is used to acquire the HTML source file of the webpage entrance; the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource;
[0100] The generating module 330 is used to generate an initial HTML file based on the HTML source file by using a preset front-end building tool; the initial HTML file includes a resource loading code for each static resource;
[0101] The replacement module 350 is used to replace each placeholder tag in the initial HTML file with the resource loading code of the corresponding static resource to obtain the target HTML file of the web page entrance.
[0102] Optionally, the replacement module 350 is also used to: obtain a resource mapping relationship between each placeholder tag and each resource loading code in the initial HTML file; and replace each placeholder tag in the initial HTML file with its matching resource loading code according to the resource mapping relationship to obtain the target HTML file for the web page entrance.
[0103] Optionally, the replacement module 350 is also used to: use a preset regular expression to identify each placeholder tag in the initial HTML file and obtain the resource identifier of each placeholder tag; for each placeholder tag, extract the resource loading code containing the resource identifier of the placeholder tag from the initial HTML file, obtain the resource loading code matched by the placeholder tag, and obtain a resource mapping relationship between each placeholder tag and the resource loading code matched by it.
[0104] In order to execute the corresponding steps of web page access in the above embodiment, a method for implementing a web page access device is provided below. Figure 5 , is a functional module diagram of a web page access device provided in an embodiment of the present invention. It should be noted that the basic principle and technical effects of the web page access device 400 provided in this embodiment are the same as those of the above embodiment. For the sake of brief description, for matters not mentioned in this embodiment, reference may be made to the corresponding contents in the above embodiment. The web page access device 400 includes:
[0105] The access module 410 is used to obtain the HTML file of the target web page entrance according to the access instruction of the target web page; the resource loading code of each static resource in the HTML file is located after the web page frame preview code;
[0106] An execution module 430 is used to execute the web page frame preview code in the HTML file to display the frame structure of the target web page;
[0107] Execute the resource loading code of each static resource in the HTML file to load each static resource of the target web page.
[0108] An embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, the HTML file generation method and / or the web page access method disclosed in the embodiment of the present invention are implemented.
[0109] The embodiment of the present invention further provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the HTML file generation method and / or the web page access method disclosed in the embodiment of the present invention are implemented.
[0110] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical functions. 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 consecutive boxes 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 and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0111] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0112] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0113] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. 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 generating an HTML file, characterized in that: The HTML file generation method comprises: Obtaining an HTML source file of a web page entrance; the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource; Generate an initial HTML file based on the HTML source file using a preset front-end building tool; the initial HTML file includes a resource loading code for each static resource; Each placeholder tag in the initial HTML file is replaced with a resource loading code of a corresponding static resource to obtain a target HTML file for a web page entrance.
2. The method for generating an HTML file according to claim 1, wherein: The position of each placeholder tag in the HTML source file is located after the position of the web page frame preview code.
3. The HTML file generation method according to claim 1 or 2, characterized in that: The step of replacing each placeholder tag in the initial HTML file with the resource loading code of the corresponding static resource to obtain the target HTML file of the webpage entrance comprises: According to each of the placeholder tags and each of the resource loading codes in the initial HTML file, a resource mapping relationship between each of the placeholder tags and the resource loading codes matched thereto is obtained; According to the resource mapping relationship, each placeholder tag in the initial HTML file is replaced with its matching resource loading code to obtain a target HTML file for the web page entrance.
4. The method for generating an HTML file according to claim 3, wherein: The placeholder tag includes a resource identifier representing a static resource; The step of obtaining a resource mapping relationship between each placeholder tag and the resource loading code matched thereto according to each placeholder tag and each resource loading code in the initial HTML file comprises: Using a preset regular expression, identifying each of the placeholder tags in the initial HTML file, and obtaining a resource identifier of each of the placeholder tags; For each placeholder tag, the resource loading code containing the resource identifier of the placeholder tag is extracted from the initial HTML file, the resource loading code matched by the placeholder tag is obtained, and a resource mapping relationship between each placeholder tag and the resource loading code matched by the placeholder tag is obtained.
5. A web page access method, characterized in that: The web page access method comprises: According to the access instruction of the target webpage, an HTML file of the entrance of the target webpage is obtained; the resource loading code of each static resource in the HTML file is located after the webpage frame preview code; Executing the webpage frame preview code in the HTML file to display the frame structure of the target webpage; Execute the resource loading code of each static resource in the HTML file to load each static resource of the target web page; Wherein, the HTML file is obtained according to the HTML file generation method according to any one of claims 1 to 4.
6. An HTML file generating device, characterized in that: The HTML file generating device comprises: An acquisition module is used to acquire an HTML source file of a web page entrance; the HTML source file includes a plurality of placeholder tags and the position of each placeholder tag is the expected position of the corresponding static resource; A generation module, used to generate an initial HTML file based on the HTML source file using a preset front-end building tool; the initial HTML file includes a resource loading code for each static resource; The replacement module is used to replace each placeholder tag in the initial HTML file with the resource loading code of the corresponding static resource to obtain the target HTML file of the web page entrance.
7. The HTML file generating device according to claim 6, characterized in that: The replacement module is also used for: According to each of the placeholder tags and each of the resource loading codes in the initial HTML file, a resource mapping relationship between each of the placeholder tags and the resource loading codes matched thereto is obtained; According to the resource mapping relationship, each placeholder tag in the initial HTML file is replaced with its matching resource loading code to obtain a target HTML file for the web page entrance.
8. A web page access device, characterized in that: The web page access device comprises: The access module is used to obtain the HTML file of the target web page entrance according to the access instruction of the target web page; the resource loading code of each static resource in the HTML file is located after the web page frame preview code; An execution module, used for executing the web page frame preview code in the HTML file to display the frame structure of the target web page; Execute the resource loading code of each static resource in the HTML file to load each static resource of the target web page; Wherein, the HTML file is obtained according to the HTML file generation method according to any one of claims 1 to 4.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, the method for generating an HTML file according to any one of claims 1 to 4 and / or the method for accessing a web page according to claim 5 is implemented.
10. A storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the method for generating an HTML file according to any one of claims 1 to 4 and / or the method for accessing a web page according to claim 5 are implemented.
Citation Information
Patent Citations
Hyper text markup language (HTML) file distributed releasing method and HTML file distributed releasing apparatus
CN106407339A
A method for optimizing Web front-end performance
CN109359253A
Application program processing method, device and equipment
CN111552473A
Webpage loading method and device
CN112364277A
Framework for dependency management and automatic file load in a network environment
US20150100879A1
