CN114064032A - Source code processing method and device, electronic equipment and storage medium - Google Patents
Source code processing method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114064032A CN114064032A CN202111344144.5A CN202111344144A CN114064032A CN 114064032 A CN114064032 A CN 114064032A CN 202111344144 A CN202111344144 A CN 202111344144A CN 114064032 A CN114064032 A CN 114064032A
- Authority
- CN
- China
- Prior art keywords
- resource
- code
- common
- page
- source code
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/451—Execution arrangements for user interfaces
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The present disclosure provides a source code processing method, including: reading, by a module packager, a source code of a target item in response to a packaging request for the target item, wherein the target item includes a plurality of pages, each page having a corresponding page source code, the page source code including a function code block; determining common code blocks in all function code blocks in a source code of a target item to obtain one or more common code blocks; packing one or more common code blocks into a first resource package and a second resource package; for each page, packaging codes except the common code block in the page source codes of the page into a third resource package; and uploading the first resource package, the second resource package and the plurality of third resource packages to the server. In addition, the present disclosure also provides a source code processing apparatus, an electronic device, a readable storage medium and a computer program product.
Description
Technical Field
The present disclosure relates to the field of front-end technologies and computer technologies, and more particularly, to a source code processing method, a source code processing apparatus, an electronic device, a readable storage medium, and a computer program product.
Background
The front end, i.e., the foreground portion of the website, is a webpage that runs on a browser of the user terminal and is shown to the user for browsing, and is also an important window for the enterprise to show business to the client. With the continuous expansion of services, the services to be processed by the source code become heavier and heavier, so that the code volume of the front end becomes larger and larger.
In the course of implementing the disclosed concept, the inventors found that there are at least the following technical problems in the related art: the service codes are seriously coupled with the public function codes and the interface component codes, the public code files obtained by packaging are large, and page rendering can be blocked during loading.
Disclosure of Invention
In view of the above, the present disclosure provides a source code processing method, a source code processing apparatus, an electronic device, a readable storage medium, and a computer program product.
One aspect of the present disclosure provides a source code processing method, including: reading a source code of a target item through a module packager in response to a packaging request for the target item, wherein the target item comprises a plurality of pages, each page has a corresponding page source code, and the page source code comprises a function code block; determining common code blocks in all the function code blocks in the source code of the target item to obtain one or more common code blocks; packing one or more common code blocks into a first resource packet and a second resource packet; for each page, packaging codes except the common code block in the page source codes of the page into a third resource packet; and uploading the first resource package, the second resource package and the plurality of third resource packages to a server.
According to an embodiment of the present disclosure, the determining a common code block of all the function code blocks in the source code of the target item includes: counting the number of times of reference of each functional code block; and determining the functional code block with the reference times larger than or equal to a first preset value as the common code block.
According to an embodiment of the present disclosure, packing one or more of the above common code blocks into a first resource packet and a second resource packet includes: determining the weight value of each common code block; packing one or more public code blocks with the weight value larger than or equal to a second preset value into a first resource packet; and packaging one or more public code blocks with the weight values smaller than the second preset value into a second resource packet.
According to an embodiment of the present disclosure, the determining the weight of each common code block includes: determining the weight of the common code block based on one or more of the following factors: reference times, update frequency and volume size of the common code block.
According to an embodiment of the present disclosure, the method further includes: based on a preset component list, packaging the common code blocks in the first resource packet into a fourth resource packet and a plurality of fifth resource packets; and uploading the second resource package, the third resource packages, the fourth resource package, and the fifth resource packages to a server, respectively.
According to an embodiment of the present disclosure, the packing the common code blocks in the first resource package into a fourth resource package and a plurality of fifth resource packages based on a preset component list includes: acquiring names of a plurality of preset components in the preset component list; for each preset component, extracting a common code block consistent with the name of the preset component from the first resource packet, and packaging the common code block into the fifth resource packet; and packaging the rest common code blocks in the first resource packet into the fourth resource packet.
Another aspect of the present disclosure provides a source code processing apparatus, including: the reading module is used for responding to a packaging request for a target item, reading the source code of the target item through a module packaging device, wherein the target item comprises a plurality of pages, each page has corresponding page source code, and the page source code comprises a function code block; a determining module, configured to determine a common code block in all the function code blocks in a source code of the target item, to obtain one or more common code blocks; a first packing module, configured to pack one or more common code blocks into a first resource packet and a second resource packet; the second packaging module is used for packaging codes except the common code block in the page source codes of the pages into a third resource package for each page; and the first uploading module is used for uploading the first resource packet, the second resource packet and the third resource packets to a server.
Another aspect of the present disclosure provides an electronic device including: one or more processors; memory to store one or more instructions, wherein the one or more instructions, when executed by the one or more processors, cause the one or more processors to implement a method as described above.
Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions for implementing the method as described above when executed.
Another aspect of the disclosure provides a computer program product comprising computer executable instructions for implementing the method as described above when executed.
According to the embodiment of the disclosure, when the source code of the target item is packaged, a common code block in the source code can be determined, the common code block is respectively packaged into a first resource packet and a second resource packet, then, for the source code of each page, the codes left after the common code block is extracted are packaged into a third resource packet, and the first resource packet, the second resource packet and a plurality of third resource packets obtained through packaging can be uploaded to a server to be used by a client. By the technical means, the technical problems that the service codes, the public function codes and the interface component codes are seriously coupled, the public code files obtained by packaging are large, and page rendering is blocked during loading are at least partially solved, so that the page loading efficiency is effectively improved, and the user experience is optimized.
Drawings
The above and other objects, features and advantages of the present disclosure will become more apparent from the following description of embodiments of the present disclosure with reference to the accompanying drawings, in which:
fig. 1 schematically shows an exemplary system architecture to which a source code processing method may be applied according to an embodiment of the present disclosure.
FIG. 2 schematically shows a flow diagram of a source code processing method according to an embodiment of the disclosure.
FIG. 3 schematically shows a flow diagram of a source code processing method according to another embodiment of the present disclosure.
FIG. 4 schematically shows a schematic diagram of a source code process flow using webpack according to yet another embodiment of the present disclosure.
Fig. 5 schematically shows a block diagram of a source code processing apparatus according to an embodiment of the present disclosure.
Fig. 6 schematically shows a block diagram of an electronic device adapted to implement a source code processing method according to an embodiment of the present disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). Where a convention analogous to "A, B or at least one of C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B or C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
The browser has a certain limit to the maximum number of requests initiated simultaneously, generally, the number of requests initiated simultaneously is required to be not more than six, and when the number of requests coming simultaneously exceeds six, the exceeding requests are queued to be processed. Under the condition of not adopting a front-end code segmentation strategy, front-end codes can be integrally packaged into a public file, and because all codes are concentrated in one file, the file size is too large, the request time is correspondingly prolonged, the blank screen time and the first screen time of a project are too long, the loading speed of a project first page is very slow, and the user experience is influenced.
In the related art, a person skilled in the art generally uses a module packer and adopts a certain packetization strategy to pack and divide the front-end code. However, the adoption of the sub-packaging strategy in the related technology often causes the same common module to be contained in the packaged files of a plurality of pages, and the repeated packaging of the same code causes the volume of the whole code to be larger; the common code base quoted in the project is also packaged into the service code, and as the service code changes frequently, the hash value of the file obtained by packaging each time changes, so that the cache of the original common code base at the front end fails, and the common code base needs to be reloaded; the common code base is still bulky after packing.
Taking the module packer webpack as an example, the webpack adopts a general sub-packaging strategy: whether a new resource package is shared or from a common module, whether the volume of the new resource package is greater than 30kb before compression, the number of concurrent requests to load resource packages on demand is less than or equal to 5, and the number of concurrent requests at initial loading of a page is less than or equal to 3. The adoption of the subpackage strategy has the following disadvantages: the third-party component library is seriously coupled with the service code; the separation rule based on 30kb does not meet the actual requirement of project production; the custom component library is often combined and packaged with other codes, and when the codes are changed, the front-end cache fails and the like.
In view of this, embodiments of the present disclosure provide a code subpackage policy, and on the basis of a subpackage policy of related technologies, public codes such as a custom component library and an interface component library are further separated, so that the volume of a single resource package is reduced, and the page loading efficiency is effectively improved.
Specifically, embodiments of the present disclosure provide a source code processing method, a source code processing apparatus, an electronic device, a readable storage medium, and a computer program product. The method comprises the steps of responding to a packaging request aiming at a target item, reading a source code of the target item through a module packaging device, wherein the target item comprises a plurality of pages, each page is provided with a corresponding page source code, and the page source code comprises a function code block; determining common code blocks in all function code blocks in a source code of a target item to obtain one or more common code blocks; packing one or more common code blocks into a first resource package and a second resource package; for each page, packaging codes except the common code block in the page source codes of the page into a third resource package; and uploading the first resource package, the second resource package and the plurality of third resource packages to the server.
Fig. 1 schematically shows an exemplary system architecture to which a source code processing method may be applied according to an embodiment of the present disclosure. It should be noted that fig. 1 is only an example of a system architecture to which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, and does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.
As shown in fig. 1, a system architecture 100 according to this embodiment may include development- side devices 101, 102, a server 103, and client devices 104, 105, 106.
The development- side apparatuses 101 and 102 may be any electronic apparatuses having a display device and an information input/output device, such as a computer, a workstation, and the like. A developer may use the development- side device 101, 102 to develop and maintain a project and upload a resource package into the server 103.
The client devices 104, 105, 106 may be a variety of electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The client devices 104, 105, 106 may have a browser application installed thereon, and the user may use the browser application in the client devices 104, 105, 106 to download the corresponding resource package from the server 103 to access the project developed by the developer.
It should be noted that the source code processing method provided by the embodiments of the present disclosure may be generally executed by the development- side devices 101 and 102. Accordingly, the source code processing apparatus provided by the embodiments of the present disclosure may be generally disposed in the development- side devices 101 and 102. The source code processing method provided by the embodiment of the present disclosure may also be executed by a server or a server cluster capable of communicating with the development- side devices 101 and 102 and/or the server 103. Accordingly, the source code processing apparatus provided by the embodiment of the present disclosure may also be disposed in a server or a server cluster capable of communicating with the development- side devices 101 and 102 and/or the server 103.
For example, after the developer completes the development work of the target project on the development end device 101, the development end device 101 may execute the source code processing method provided by the embodiment of the present disclosure, or the source code of the target project may be sent to a server or a server cluster capable of communicating with the development end devices 101 and 102 and/or the server 103, and the server or the server cluster receiving the target project executes the source code processing method provided by the embodiment of the present disclosure, so as to package and send the source code to the server 103.
It should be understood that the number of developer devices, servers, and client devices in fig. 1 is merely illustrative. There may be any number of originating devices, servers, and client devices, as desired for an implementation.
FIG. 2 schematically shows a flow diagram of a source code processing method according to an embodiment of the disclosure.
As shown in fig. 2, the method includes operations S201 to S205.
In operation S201, in response to a packaging request for a target item, reading, by a module packager, a source code of the target item, wherein the target item includes a plurality of pages, each page having a corresponding page source code, and the page source code includes a function code block.
In operation S202, a common code block of all function code blocks in the source code of the target item is determined, resulting in one or more common code blocks.
In operation S203, one or more common code blocks are packed into a first resource package and a second resource package.
In operation S204, for each page, codes except for the common code block in the page source code of the page are packed into a third resource package.
In operation S205, the first resource package, the second resource package, and a plurality of third resource packages are uploaded to a server.
According to an embodiment of the present disclosure, the source code of the target item may be the front-end code of the target item.
According to embodiments of the present disclosure, the module packager may be any tool for packaging applications, such as webpack, and the like.
According to the embodiment of the disclosure, the plurality of pages may include a first page and a plurality of other pages, and the browser may preferentially load the first page when loading the target item.
According to the embodiment of the disclosure, the page source code of the page may include a service code block and a plurality of function code blocks. The plurality of function code blocks may be respectively subordinate to a base code library, an interface code library and a custom tool library, and the function code blocks in the base code library, the interface code library and the custom tool library may all be determined to be a common code block.
According to an embodiment of the present disclosure, whether a function code block is a common code block may be determined based on different policies. For example, a common code block list may be set in advance, and a common code block may be determined from a plurality of function code blocks based on a code block name or an identifier recorded in the list; alternatively, the number of references of each function code block may be recorded, and the function code block with the larger number of references may be identified as the common code block.
According to the embodiment of the disclosure, in order to avoid the problem of slow loading speed caused by large volume of the resource packet packed by the common code blocks, the obtained one or more common code blocks can be separately packed based on different strategies. For example, the common code blocks with larger volumes can be separately packed by separating according to the sizes of the common code blocks; or, the code blocks can be separated according to the update frequency of the common code block, so that the code blocks with larger update frequency difference are prevented from being packed in the same resource packet.
According to the embodiment of the disclosure, after the common code block is extracted, the remaining codes of each page can be packed into a third resource packet. The remaining codes may be traffic code blocks only or traffic code blocks and functional code blocks not shared.
According to the embodiment of the disclosure, after the resource package is packaged, the resource package can be distributed through a Content Delivery Network (CDN), that is, the packaged resource packages are sequentially uploaded to servers deployed in various places, and a user can obtain the resource package from the nearest server nearby, so that Network congestion is effectively reduced, and the user access response speed is increased.
According to the embodiment of the disclosure, when the source code of the target item is packaged, a common code block in the source code can be determined, the common code block is respectively packaged into a first resource packet and a second resource packet, then, for the source code of each page, the codes left after the common code block is extracted are packaged into a third resource packet, and the first resource packet, the second resource packet and a plurality of third resource packets obtained through packaging can be uploaded to a server to be used by a client. By the technical means, the technical problems that the service codes, the public function codes and the interface component codes are seriously coupled, the public code files obtained by packaging are large, and page rendering is blocked during loading are at least partially solved, so that the page loading efficiency is effectively improved, and the user experience is optimized.
The method of fig. 2 is further described with reference to fig. 3 and 4 in conjunction with specific embodiments.
FIG. 3 schematically shows a flow diagram of a source code processing method according to another embodiment of the present disclosure.
As shown in fig. 3, the method includes operations S301 to S313.
It should be noted that, unless explicitly stated that there is an execution sequence between different operations or there is an execution sequence between different operations in technical implementation, the execution sequence between multiple operations may not be sequential, or multiple operations may be executed simultaneously in the flowchart in this disclosure.
In operation S301, source code of a target item is loaded.
In operation S302, the number of references of each function code block in the source code is counted.
In operation S303, it is determined whether the number of references is less than a first preset value for each function code block. In a case where it is determined that the number of times of reference of the function code block is less than the first preset value, performing operation S304; in a case where it is determined that the number of times of reference of the function code block is greater than or equal to the first preset value, operation S306 is performed.
In operation S304, the function code block is marked as a private code block.
In operation S305, the private code blocks of each page are packed into a third resource package.
In operation S306, the function code block is marked as a common code block.
In operation S307, weight values of the common code blocks are determined.
In operation S308, it is determined whether the weight value is less than a second preset value for each common code block. In a case where it is determined that the weight of the common code block is less than the second preset value, performing operation S309; in case that it is determined that the weight value of the common code block is greater than or equal to the second preset value, operation S311 is performed.
In operation S309, the common code block is marked as a second type code block.
In operation S310, all common code blocks marked as code blocks of the second type are packed into a second resource package.
In operation S311, the common code block is marked as a first type code block.
In operation S312, all common code blocks marked as code blocks of the first type are packed into a first resource package.
After the execution of operations S305, S310, or S312 is completed, operation S313 may be performed.
In operation S313, the resource package is uploaded to the server.
According to the embodiments of the present disclosure, a functional code block whose number of references is greater than or equal to a first preset value may be determined as a common code block.
According to the embodiment of the disclosure, the first preset value can be set according to a specific application scene. When the value of the first preset value is small, for example, set to 2, 3, etc., most common code blocks can be extracted from the source code; on the other hand, however, it is also possible to mark code blocks that are less common but have a higher update frequency as common code blocks; because the resource packet packed by the common code block is usually large in volume, the higher update frequency causes the client to need to frequently reload the resource packet, thereby increasing the consumption of network resources. When the value of the first preset value is large, for example, set to 5, 7, etc., the volume of the resource packet packed by each page may be large, so as to slow down the loading speed of the resource packet.
In some embodiments, the discrimination of the common code block may also be made in conjunction with the size of the functional code block. For example, a functional code block having a size of more than 30kb with a number of references of 2 or more may be selected as the common code block. According to the embodiment of the disclosure, a developer may set a weight value for each common code block, and the size of the weight value of a common code block may be determined according to any one or combination of factors such as the number of references of the common code block, the update frequency, and the volume size.
For example, the common code blocks in the source code of the target item all belong to one of the base code library, the interface component library and the custom tool library, as shown in table 1.
TABLE 1
Type (B) | Number of references | Update frequency | Size of the volume | Weight value |
Basic code library | Height of | Is low in | Big (a) | Is low in |
Interface component library | Height of | In | Big (a) | In |
Custom tool library | Height of | Height of | In | Height of |
For the basic code block, the basic code library comprises all basic components for supporting the running of the program, and the components in the basic code library are required to be applied in the source codes of all pages, so that the basic code library has higher reference times; the updating frequency of the basic code base is generally consistent with that of the program compiling software, and the updating frequency is low; the basic code library includes basic components for realizing functions, and thus the basic code library is generally large in size. Because the updating frequency of the basic code base is low and the size is large, a low weight value can be set for the public code block belonging to the basic code base.
For the interface component library, each page needs to use the components in the interface component library when being displayed, so the interface component library also has higher reference times; in the actual generation, the art style of the page generally does not need to be updated frequently, for example, the interface component library may be subject to seasons, and is generally updated once every several months, and the update frequency may be set to be medium; the resource files for realizing the interface such as pictures, icons and the like are generally large in volume, so that the volume of the interface component library is generally large. Because the update frequency of the interface component library is generally higher than that of the basic code library, a weight value which is larger than that of the basic code library can be set for the public code block of the home interface component library.
For custom tool libraries, a custom tool library may be a library created by a developer to implement a particular function, which may be maintained by multiple developers, referenced by multiple pages of source code, and thus may have a higher number of references and a higher update frequency, but is generally smaller in size than the base code library and the interface component library. Because the custom tool library is modified more frequently, in order to avoid that the modification of the custom tool library causes the hash values of other files to be invalid, a larger weight value can be set for the custom tool library.
According to the embodiment of the disclosure, a developer can also set a second preset value, and the size of the second preset value can be set according to a specific application scene. For example, the second preset value may be set to be greater than the weight of the basic code library and less than the weight of the interface component library; through the setting of the second preset value, the public code blocks belonging to the basic code base can be extracted and packaged into the second resource packet, so that the influence of frequent downloading of data packets with larger volume on user experience is avoided as much as possible.
According to the embodiment of the disclosure, the common code blocks with the weights greater than or equal to the second preset value can be packed into the first resource packet; and packaging the common code blocks with the weight values smaller than a second preset value into a second resource packet.
According to the embodiment of the disclosure, by setting the weight and performing the sub-packaging of the common code blocks according to the weight, the probability of cache failure of each resource packet can be effectively reduced, and the loading speed of the page is increased. For example, when the weight is set by combining the update frequency and the volume size, the code blocks with higher update frequency but smaller volume and the code blocks with lower update frequency but larger volume can be prevented from being packed in one resource packet after being packed, and frequent reloading of the resource packet in which the code blocks with lower update frequency but larger volume are located is avoided.
In some embodiments, the developer may further set a preset component list, and according to the preset component list, the common code blocks in the first resource package may be further packaged into a fourth resource package and a plurality of fifth resource packages.
According to an embodiment of the present disclosure, the preset component list may include names of a plurality of preset components, and the preset components may be, for example, components belonging to an interface component library or a custom tool library.
According to the embodiment of the disclosure, through the preset component list, the common code blocks consistent with the names of the preset components included in the list can be extracted from the first resource packet, and the common code blocks corresponding to each preset component are respectively packaged into a fifth resource packet; the common code blocks in the remaining first resource package may be packed into a fourth resource package.
According to the embodiment of the disclosure, the fourth resource package and the fifth resource packages obtained by packaging can be uploaded to the server instead of the first resource package.
FIG. 4 schematically shows a schematic diagram of a source code process flow using webpack according to yet another embodiment of the present disclosure.
As shown in FIG. 4, the source code processing flow implemented using webpack includes operations S401-S405.
Asynchronous packetization is performed using webpack in operation S401.
In operation S402, the common code file is extracted as vendor.
In operation S403, a base code library file is custom extracted from the vendor.
In operation S404, an interface component library file is custom-extracted from the vendor.
In operation S405, the extracted files are packaged respectively.
According to the embodiment of the present disclosure, the source code of the portal page of the target project is packaged into one main.js and the source code of each page other than the portal page is packaged into one bundle.js by asynchronous packetization.
According to the embodiment of the disclosure, by setting the number of times of the common reference of the cacheGroup to be 2, the common code file referred to above twice in main.
According to the embodiment of the disclosure, the sizes of main.js and vendor.js are greatly optimized by extracting the public code file; when the first screen is loaded, main and other JS files can be downloaded in parallel, and the first screen time is greatly optimized.
According to the embodiment of the disclosure, by configuring the weight and the extraction priority of the code block, updated low-frequency basic code library files such as echarts and ant-design can be extracted from the vendor.js in a customized manner, and the files are packed into common.js, so that the size of the vendor.js packet is further separated, the front-end cache is utilized to the maximum extent, the speed of a user accessing a website for two times or more is reduced, and the user experience is optimized.
According to the embodiment of the disclosure, interface component library files such as component and utils can be extracted from the vendor. JS in a customized manner and packaged into separate JS files respectively.
According to the embodiment of the disclosure, the service code and the public code file are completely separated, so that the problem of cache failure of the public code file caused by service code change is avoided, the size of a single JS file is effectively reduced, a plurality of JS files can be requested in parallel by using the parallel downloading function of the browser, and the access speed of the webpage is improved.
Fig. 5 schematically shows a block diagram of a source code processing apparatus according to an embodiment of the present disclosure.
As shown in fig. 5, the source code processing apparatus 500 includes a reading module 510, a determining module 520, a first packing module 530, a second packing module 540, and a first uploading module 550.
A reading module 510, configured to read, by a module packager, a source code of a target item in response to a packaging request for the target item, where the target item includes multiple pages, each page has a corresponding page source code, and the page source code includes a function code block.
A determining module 520, configured to determine a common code block in all the function code blocks in the source code of the target item, to obtain one or more common code blocks.
A first packing module 530, configured to pack one or more of the common code blocks into a first resource package and a second resource package.
A second packing module 540, configured to, for each page, pack codes, except for the common code block, in the page source code of the page into a third resource package.
A first uploading module 550, configured to upload the first resource package, the second resource package, and the plurality of third resource packages to a server.
According to the embodiment of the disclosure, when the source code of the target item is packaged, a common code block in the source code can be determined, the common code block is respectively packaged into a first resource packet and a second resource packet, then, for the source code of each page, the codes left after the common code block is extracted are packaged into a third resource packet, and the first resource packet, the second resource packet and a plurality of third resource packets obtained through packaging can be uploaded to a server to be used by a client. By the technical means, the technical problems that the service codes, the public function codes and the interface component codes are seriously coupled, the public code files obtained by packaging are large, and page rendering is blocked during loading are at least partially solved, so that the page loading efficiency is effectively improved, and the user experience is optimized.
According to an embodiment of the present disclosure, the determination module 520 includes a first determination unit and a second determination unit.
And the first determining unit is used for counting the reference times of each functional code block.
And the second determining unit is used for determining the functional code block with the reference frequency larger than or equal to a first preset value as the common code block.
According to an embodiment of the present disclosure, the first packing module 530 includes a first packing unit, a second packing unit, and a third packing unit.
And the first packing unit is used for determining the weight of each common code block.
And the second packing unit is used for packing one or more public code blocks with the weight values larger than or equal to a second preset value into a first resource packet.
And the third packing unit is used for packing one or more public code blocks with weights smaller than the second preset value into a second resource packet.
According to an embodiment of the present disclosure, the first packing unit is configured to determine the weight of the common code block based on one or more of the following factors: reference times, update frequency, and volume size of the common code block.
According to an embodiment of the present disclosure, the apparatus 500 further includes a third packing module and a second uploading module.
And the third packaging module is used for packaging the common code blocks in the first resource package into a fourth resource package and a plurality of fifth resource packages based on a preset component list.
And the second uploading module is used for respectively uploading the second resource packet, the plurality of third resource packets, the fourth resource packet and the plurality of fifth resource packets to a server.
According to an embodiment of the present disclosure, the third packing module includes a fourth packing unit, a fifth packing unit, and a sixth packing unit.
And the fourth packing unit is used for acquiring the names of a plurality of preset components in the preset component list.
And a fifth packing unit, configured to, for each preset component, extract a common code block that is consistent with the name of the preset component from the first resource package, and pack the common code block into the fifth resource package.
A sixth packing unit, configured to pack the remaining common code blocks in the first resource packet into the fourth resource packet.
Any number of modules, sub-modules, units, sub-units, or at least part of the functionality of any number thereof according to embodiments of the present disclosure may be implemented in one module. Any one or more of the modules, sub-modules, units, and sub-units according to the embodiments of the present disclosure may be implemented by being split into a plurality of modules. Any one or more of the modules, sub-modules, units, sub-units according to embodiments of the present disclosure may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in any other reasonable manner of hardware or firmware by integrating or packaging a circuit, or in any one of or a suitable combination of software, hardware, and firmware implementations. Alternatively, one or more of the modules, sub-modules, units, sub-units according to embodiments of the disclosure may be at least partially implemented as a computer program module, which when executed may perform the corresponding functions.
For example, any plurality of the reading module 510, the determining module 520, the first packing module 530, the second packing module 540, and the first uploading module 550 may be combined and implemented in one module/unit/sub-unit, or any one of the modules/units/sub-units may be split into a plurality of modules/units/sub-units. Alternatively, at least part of the functionality of one or more of these modules/units/sub-units may be combined with at least part of the functionality of other modules/units/sub-units and implemented in one module/unit/sub-unit. According to an embodiment of the present disclosure, at least one of the reading module 510, the determining module 520, the first packing module 530, the second packing module 540, and the first uploading module 550 may be at least partially implemented as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented by hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or implemented by any one of three implementations of software, hardware, and firmware, or an appropriate combination of any several of them. Alternatively, at least one of the reading module 510, the determining module 520, the first packing module 530, the second packing module 540, and the first uploading module 550 may be at least partially implemented as a computer program module, which when executed, may perform a corresponding function.
It should be noted that the source code processing apparatus portion in the embodiment of the present disclosure corresponds to the source code processing method portion in the embodiment of the present disclosure, and the description of the source code processing apparatus portion specifically refers to the source code processing method portion, which is not described herein again.
Fig. 6 schematically shows a block diagram of an electronic device adapted to implement a source code processing method according to an embodiment of the present disclosure. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 6, a computer electronic device 600 according to an embodiment of the present disclosure includes a processor 601, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. Processor 601 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 601 may also include onboard memory for caching purposes. Processor 601 may include a single processing unit or multiple processing units for performing different actions of a method flow according to embodiments of the disclosure.
In the RAM 603, various programs and data necessary for the operation of the electronic apparatus 600 are stored. The processor 601, the ROM602, and the RAM 603 are connected to each other via a bus 604. The processor 601 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM602 and/or RAM 603. It is to be noted that the programs may also be stored in one or more memories other than the ROM602 and RAM 603. The processor 601 may also perform various operations of the method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to embodiments of the present disclosure, method flows according to embodiments of the present disclosure may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program, when executed by the processor 601, performs the above-described functions defined in the system of the embodiments of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. Examples may include, but are not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM602 and/or RAM 603 described above and/or one or more memories other than the ROM602 and RAM 603.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method provided by the embodiments of the present disclosure, when the computer program product is run on an electronic device, the program code being adapted to cause the electronic device to carry out the source code processing method provided by the embodiments of the present disclosure.
The computer program, when executed by the processor 601, performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed in the form of a signal on a network medium, downloaded and installed through the communication section 609, and/or installed from the removable medium 611. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions. Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.
Claims (10)
1. A source code processing method, comprising:
reading, by a module packager, a source code of a target item in response to a packaging request for the target item, wherein the target item includes a plurality of pages, each of the pages having a corresponding page source code, the page source code including a block of function code;
determining common code blocks in all the function code blocks in the source code of the target item to obtain one or more common code blocks;
packing one or more of the common code blocks into a first resource package and a second resource package;
for each page, packaging codes except the common code block in page source codes of the page into a third resource packet; and
uploading the first resource package, the second resource package, and the plurality of third resource packages to a server.
2. The method of claim 1, wherein the determining a common code block of all the function code blocks in the source code of the target item comprises:
counting the number of times of reference of each function code block; and
and determining the functional code block with the reference times larger than or equal to a first preset value as the common code block.
3. The method of claim 1, wherein packing one or more of the common code blocks into a first resource package and a second resource package comprises:
determining the weight value of each common code block;
one or more public code blocks with the weight values larger than or equal to a second preset value are packaged into a first resource packet; and
and packing one or more public code blocks with the weight values smaller than the second preset value into a second resource packet.
4. The method of claim 3, wherein the determining the weight values of each of the common code blocks comprises:
determining weights for the common code blocks based on one or more of: reference times, update frequency, and volume size of the common code block.
5. The method of claim 1, further comprising:
based on a preset component list, packaging the common code blocks in the first resource packet into a fourth resource packet and a plurality of fifth resource packets; and
and uploading the second resource packet, the third resource packets, the fourth resource packet and the fifth resource packets to a server respectively.
6. The method of claim 5, wherein the packing the common code blocks in the first resource package into a fourth resource package and a plurality of fifth resource packages based on a preset component list comprises:
acquiring names of a plurality of preset components in the preset component list;
for each preset component, extracting a common code block consistent with the name of the preset component from the first resource packet, and packaging the common code block into a fifth resource packet; and
and packaging the rest common code blocks in the first resource packet into the fourth resource packet.
7. A source code processing apparatus, comprising:
the reading module is used for responding to a packaging request for a target item, reading the source code of the target item through a module packaging device, wherein the target item comprises a plurality of pages, each page has corresponding page source code, and the page source code comprises a function code block;
a determining module, configured to determine a common code block in all the function code blocks in a source code of the target item, to obtain one or more common code blocks;
a first packing module, configured to pack one or more common code blocks into a first resource packet and a second resource packet;
the second packaging module is used for packaging codes except the common code block in the page source codes of the pages into a third resource package for each page; and
a first uploading module, configured to upload the first resource package, the second resource package, and the plurality of third resource packages to a server.
8. An electronic device, comprising:
one or more processors;
a memory to store one or more instructions that,
wherein the one or more instructions, when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
9. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to carry out the method of any one of claims 1 to 6.
10. A computer program product comprising computer executable instructions for implementing the method of any one of claims 1 to 6 when executed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111344144.5A CN114064032A (en) | 2021-11-12 | 2021-11-12 | Source code processing method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111344144.5A CN114064032A (en) | 2021-11-12 | 2021-11-12 | Source code processing method and device, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114064032A true CN114064032A (en) | 2022-02-18 |
Family
ID=80271806
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111344144.5A Pending CN114064032A (en) | 2021-11-12 | 2021-11-12 | Source code processing method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114064032A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115982491A (en) * | 2023-03-20 | 2023-04-18 | 建信金融科技有限责任公司 | Page updating method and device, electronic equipment and computer readable storage medium |
CN116991380A (en) * | 2023-09-21 | 2023-11-03 | 腾讯科技(深圳)有限公司 | Application program construction method and device, electronic equipment and storage medium |
-
2021
- 2021-11-12 CN CN202111344144.5A patent/CN114064032A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115982491A (en) * | 2023-03-20 | 2023-04-18 | 建信金融科技有限责任公司 | Page updating method and device, electronic equipment and computer readable storage medium |
CN116991380A (en) * | 2023-09-21 | 2023-11-03 | 腾讯科技(深圳)有限公司 | Application program construction method and device, electronic equipment and storage medium |
CN116991380B (en) * | 2023-09-21 | 2024-01-09 | 腾讯科技(深圳)有限公司 | Application program construction method and device, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
AU2017337061B2 (en) | Managed container instances | |
US10241843B2 (en) | Application processing allocation in a computing system | |
US9495197B2 (en) | Reliable and scalable image transfer for data centers with low connectivity using redundancy detection | |
US20200004571A1 (en) | Operating system customization in an on-demand network code execution system | |
US8442955B2 (en) | Virtual machine image co-migration | |
US11093148B1 (en) | Accelerated volumes | |
US20210349699A1 (en) | Automatic containerization of operating system distributions | |
US10409649B1 (en) | Predictive load balancer resource management | |
CN114064032A (en) | Source code processing method and device, electronic equipment and storage medium | |
US10701154B2 (en) | Sharding over multi-link data channels | |
US20150195143A1 (en) | Discovering resources of a distributed computing environment | |
CN113468456A (en) | Webpage rendering method and device, electronic equipment and computer-readable storage medium | |
CN115982491A (en) | Page updating method and device, electronic equipment and computer readable storage medium | |
US11327811B2 (en) | Distributed computing mesh | |
CN111753226A (en) | Page loading method and device | |
US20150149615A1 (en) | Process cage providing attraction to distributed storage | |
US20140165059A1 (en) | Hardware contiguous memory region tracking | |
CN107453950B (en) | Information processing method and monitoring system | |
US10795540B2 (en) | Visualizing migration of a resource of a distributed computing environment | |
CN111445274A (en) | Configurable packaging method and device based on advertisement platform and computing equipment | |
US8745620B2 (en) | Software tool and method for updating a virtual appliance | |
CN113377376A (en) | Data packet generation method, data packet generation device, electronic device, and storage medium | |
US9953037B1 (en) | Accelerating file downloads | |
US20150248347A1 (en) | Content providing apparatus and method, and computer program product | |
US11017032B1 (en) | Document recovery utilizing serialized data |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |