WO2016155525A1 - 一种加载页面模块的方法和设备 - Google Patents

一种加载页面模块的方法和设备 Download PDF

Info

Publication number
WO2016155525A1
WO2016155525A1 PCT/CN2016/076831 CN2016076831W WO2016155525A1 WO 2016155525 A1 WO2016155525 A1 WO 2016155525A1 CN 2016076831 W CN2016076831 W CN 2016076831W WO 2016155525 A1 WO2016155525 A1 WO 2016155525A1
Authority
WO
WIPO (PCT)
Prior art keywords
module
task
page
determining
processed
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.)
Ceased
Application number
PCT/CN2016/076831
Other languages
English (en)
French (fr)
Inventor
屈传鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Publication of WO2016155525A1 publication Critical patent/WO2016155525A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/44Arrangements for executing specific programs

Definitions

  • the present application relates to the field of network technologies, and in particular, to a method and a device for loading a page module.
  • each module has an entry method (such as the method of using the variable init method to represent the entry).
  • the framework will call each module's init method one by one to complete the rendering of all modules. , register interactive events, etc.
  • the execution order of multiple modules is fixed, and the module with the lower execution order will be rendered later.
  • only the delayed call function statement can be added to the init method of other modules. Delaying the execution of other modules, this method will make the coupling between modules higher, which will result in lower module execution efficiency.
  • the current page module loading method is to call each module one by one. If the module with the lower order is to be executed first, the delay calling function needs to be added to the program corresponding to other modules, so the connection between the modules will become closer. , which in turn leads to strong coupling between modules.
  • the method and device for loading a page module provided by the embodiment of the present application are used to solve the loading method of the page module existing in the prior art, and each module is called one by one. Delayed calling function statements are added to the program corresponding to the module, but delaying the calling function causes a high degree of coupling between modules.
  • a method for loading a page module is provided by an embodiment of the present application, where the method includes:
  • Determining the task with the highest priority that is currently unprocessed according to the set task processing sequence is the task that needs to be processed currently;
  • the current task to be processed in the module is sequentially called, and the step of determining that the currently unprocessed task with the highest priority is the current task to be processed is returned until the page is called. All tasks in all modules.
  • the embodiment of the present application determines each task of each module in the page, and sequentially invokes the tasks of the same task processing order in each module in the page according to the set module calling sequence. Since the module calling sequence and the task processing order can be set as needed, when the module or the task in the order of priority is required to be executed, the task priority of the corresponding task in the module can be set to a higher priority. There is no need to add additional delay calling functions to the programs corresponding to other modules, so the connection between the modules is not increased, and the coupling between the modules is reduced.
  • the task processing sequence corresponding to the page is determined according to the correspondence between the preset page and the task processing sequence.
  • the embodiment of the present application can determine the task processing order in different manners, it can meet the requirements of more different processing sequences, thereby increasing the variety of ways of loading the page modules.
  • the module calling sequence corresponding to the page is determined according to the correspondence between the preset page and the module calling sequence.
  • the embodiment of the present application can determine the module calling sequence in different manners, it can meet the requirements of more different processing sequences, thereby increasing the variety of ways of loading the page modules.
  • each task for each module in the page it also includes:
  • the corresponding operations that need to be performed at the same time are taken as a task of the module.
  • each task for each module in the page it also includes:
  • Identify each task for each module in the page including:
  • Each task of each module in the page is determined according to a task stored in the cache area.
  • the method further includes:
  • the task currently required to be processed in the determined module is called in turn.
  • the priority of the listening task in the listening module is higher than the priority of the broadcast task in the broadcast module.
  • the broadcast event in the page can be realized only by setting the priority order of the listening module and the broadcasting module that execute the broadcast event.
  • an apparatus for loading a page module provided by the embodiment of the present application includes:
  • a first determining module configured to determine each task of each module in the page, where the task is an operation corresponding to the loading module
  • a second determining module configured to determine, according to the set task processing sequence, that the currently unprocessed task with the highest priority is the task that needs to be processed currently;
  • a processing module configured to sequentially invoke the current task to be processed in the module according to the set module calling sequence, and trigger the second determining module to perform a task that determines that the currently unprocessed highest priority task is currently processed. The steps of the task until all tasks of all modules in the page are called.
  • the second determining module is further configured to determine a task processing sequence according to the following manner:
  • the task processing sequence corresponding to the page is determined according to the correspondence between the preset page and the task processing sequence.
  • processing module is further configured to determine a module calling sequence according to the following manner:
  • Determining a module calling sequence corresponding to the currently required task according to a preset relationship between the preset task and the module calling sequence; and/or determining a module corresponding to the page according to a correspondence between the preset page and the module calling sequence The order of the calls.
  • the first determining module is further configured to:
  • the first determining module is further configured to:
  • All tasks corresponding to each module in the page are stored into the buffer area before each task of each module in the page is determined; and each module in the page is determined according to the task stored in the buffer area Every task.
  • processing module is further configured to:
  • the priority of the listening task in the listening module is higher than the priority of the broadcast task in the broadcast module.
  • FIG. 1 is a schematic diagram of a method for loading a page module according to an embodiment of the present application
  • FIG. 2 is a schematic diagram of a page module distribution according to an embodiment of the present application.
  • FIG. 3 is a schematic overall flowchart of a method for loading a page module according to an embodiment of the present disclosure
  • FIG. 4 is a schematic diagram of an overall process of loading a page module in a browser according to an embodiment of the present application
  • FIG. 5 is a schematic structural diagram of a loading page module according to an embodiment of the present application.
  • the embodiment of the present application determines each task of each module in the page, and sequentially invokes the tasks of the same task processing order in each module in the page according to the set module calling sequence. Since the module calling sequence and the task processing order can be set as needed, when the module or the task in the order of priority is required to be executed, the task priority of the corresponding task in the module can be set to a higher priority. There is no need to add additional delay calling functions to the programs corresponding to other modules, so the connection between the modules is not increased, and the coupling between the modules is reduced.
  • a method for loading a page module provided by an embodiment of the present application includes:
  • Step 101 Determine each task of each module in the page, where the task is an operation corresponding to loading the module;
  • Step 102 Determine, according to the set task processing sequence, that the task with the highest priority that is currently unprocessed is the task that needs to be processed currently;
  • Step 103 In accordance with the set module calling sequence, sequentially call the task currently needed to be processed in the module, and return a step of determining that the currently unprocessed task with the highest priority is the currently required task, until the page is called. All tasks for all modules.
  • the division of the modules involved in the embodiment of the present application, the setting of the task processing sequence, and the setting of the module calling sequence may all be set according to actual needs of the user.
  • the page module needs to be loaded For example, when the user needs to open the browser to open the webpage, or when the user opens the webpage through the mobile client, the modular programming implementation is used to load the content in each module separately. In turn, the content of the entire page is displayed.
  • the prior art treats all operations corresponding to each module in the page as an init method, that is, one module corresponds to one init method.
  • the operations corresponding to each module in the page that need to be performed simultaneously are regarded as one task (ie, an init method). That is to say, each module in the embodiment of the present application corresponds to at least one init method.
  • the module includes an advertisement space that needs to be rendered, and displays a binding interaction event (such as an image carousel event, and an event that automatically pops up a drop-down box to promptly input content when the input box is input). ), animations that need to be rendered, and rendered audio.
  • a binding interaction event such as an image carousel event, and an event that automatically pops up a drop-down box to promptly input content when the input box is input.
  • the advertisement space for the page and the animation that needs to be rendered are presented to the user at the same time according to actual needs, so the rendered advertisement space and the animation to be rendered need to be executed simultaneously, and other display binding interactions in the module are performed.
  • the event and the audio that needs to be rendered also need to be presented to the user at the same time; therefore, the operation corresponding to the rendered advertisement bit and the operation corresponding to the rendered animation can be regarded as a task, and the operation corresponding to the binding interaction event and the corresponding corresponding to the rendered audio are displayed.
  • the operation as a task.
  • FIG. 2 is a schematic diagram of a page module distribution provided by an embodiment of the present application; And divide the page of the first screen into 4 modules (ie, module 1, module 2, module 3, and module 4).
  • the embodiment of the present application is divided into four modules only by the first page of a certain page, and each module corresponds to task 1, task 2, and task 3
  • the task is described in detail as an example, but it does not mean that the embodiment of the present application has only one form.
  • Other pages that divide the number of modules are also applicable to the method of the embodiment of the present application.
  • the embodiment of the present application divides each module into multiple tasks according to requirements, and can process each task in the module according to the set task execution order and the order of calling each module.
  • the set task processing sequence determine that the task with the highest priority that is currently unprocessed is the task that needs to be processed currently.
  • the task processing sequence has multiple setting modes, which can be set according to actual needs; for example, the execution order of tasks can be preset according to needs.
  • the business hopes that the data of this piece is first loaded to obtain more exposure and click rate, and at the same time, in order to highlight the content of the advertisement and attract the user's eye, the corresponding need to be rendered in the module.
  • Animations also need to be executed first; other display binding interaction events and audios that need to be rendered in the module do not need to be executed first; therefore, when setting the task processing order, you can set the rendering advertisements and rendering animations that need to be executed first.
  • the priority of the corresponding task is higher than the priority of the task corresponding to the display binding interaction event that does not need to be executed first and then the audio is rendered.
  • the parameters can be configured when instantiating:
  • order is an array, which specifies that init1 (ie task 1) of all modules is executed first, then init2 (ie task 2) and init3 (ie task 3) of all modules are executed.
  • the specification of the order can form a specification.
  • task 1 is the task with the highest priority in the task processing order. It cannot be used casually, and the task that needs the highest priority can be placed in task 1.
  • the operations corresponding to each module in the page need to be performed simultaneously as a task, and the task processing order of all tasks is set as needed, assuming that a page includes three tasks.
  • the priority of the preset task processing sequence is task 1, task 2, and task 3 from high to low.
  • the specific operations included in each task can be set according to user needs. The following assumes the operations included in each task.
  • Task 1 You can use the relevant operations of the rendering corresponding to the content that needs to be rendered by JS in a module on the first screen of the page. The business needs to be rendered first, such as the corresponding operation corresponding to the rendering of the ad slot. The task with the highest priority.
  • Task 2 The initialization method of the common module in the first screen (such as non-rendering operation), such as the related operation corresponding to the binding interaction event, can be used as the priority second task.
  • Task 3 The related operations corresponding to the initialization method of the non-first-screen module may be performed as needed, such as the related operation corresponding to the rendering of the advertisement slot in the non-first-screen module, or the correlation corresponding to the display of the binding interaction event in the non-first-screen module.
  • the operation is the third priority task.
  • task 1, task 2, and task 3 are only for convenience of description of the embodiments of the present application, but the embodiments of the present application are not limited to the scenarios applicable to the above examples, and other scenarios related to loading pages are also applicable to the present application. Methods.
  • the above tasks 1, task 2, task 3, and page are divided into four modules as an example.
  • the following tasks are the tasks with the highest priority and the tasks with the highest priority.
  • the second task of the level the task 3 represents the task of the third priority; and the four modules are represented by module 1, module 2, module 3 and module 4, respectively.
  • the task processing sequence is determined according to the following manner: determining a task processing sequence corresponding to the page according to the correspondence between the preset page and the task processing order.
  • different task processing sequences can be set for tasks in different pages as needed, and the task processing order corresponding to the current page needs to be determined according to the correspondence between the page and the task processing order. For example, suppose the task processing order of the A page is Task 1, Task 2, and Task 3; and in the B page, it may be more reasonable to set the task processing order to Task 2, Task 1, and Task 3. Therefore, when determining the task processing order, it is necessary to determine the correspondence between the page and the task processing order. If the page is A, the task processing order is task 1, task 2, task 3; if it is the B page, the task processing order is task 2 , task 1, task 3.
  • the task with the highest priority that is currently unprocessed is determined to be the task that needs to be processed currently; or the example is as shown in Figure 2, and the page is the A page, and the task processing sequence corresponding to the A page is task 1, task 2 , task 3.
  • module 1 includes task 1, task 2, task 3; module 2 includes task 1, task 2; module 3 includes task 2; and module 4 includes task 2, task 3. Therefore, according to the set task processing order, the task 1, the task 2, and the task 3 determine that the task 1 with the highest priority that is currently unprocessed is the task that needs to be processed currently.
  • the method for determining the task processing order is not limited to the above-described manner according to the page determination, and other methods capable of determining the task processing order are also applicable to the method of the present application.
  • step 102 After determining the task that needs to be processed currently, when processing the task that needs to be processed currently, it is necessary to eliminate the module that does not contain the task that needs to be processed. Specifically, after step 102, before step 103, it is determined that all the tasks of each module include modules of tasks currently to be processed; and the tasks currently required to be processed in the determined modules are sequentially called.
  • module 1 includes task 1, task 2, task 3; module 2 includes task 1, task 2; module 3 includes task 2; and module 4 includes task 2, task 3 . Therefore, according to the set task processing order of task 1, task 2, and task 3, it is determined that the task 1 with the highest priority that is currently unprocessed is the task that needs to be processed, and it is determined that the four modules of the A page contain the current needs.
  • the modules of the processed task 1, namely the module 1 and the module 2, in turn call the tasks 1 currently to be processed in the modules 1 and 2.
  • the four modules of the A page contain the modules of the task 2 that need to be processed currently, namely, the module 1, the module 2, the module 3, and the module 4, and sequentially the modules 1, 2, Calls 2 of 3 and 4 that need to be processed currently.
  • the tasks with the highest priority among the remaining tasks are judged and called.
  • sequentially calling the task currently needed to be processed in the module and returning the step of determining that the currently unprocessed task with the highest priority is the currently required task, until the page is called. All tasks in all modules.
  • the task with the highest priority among the remaining tasks is the task currently to be processed, and is determined according to the foregoing method.
  • the task that currently needs to be processed is called until all tasks of all modules in the page are called.
  • the task 3 with the highest priority that is currently unprocessed is the task that needs to be processed currently, and the modules of the task 3 that need to be processed in the four modules of the A page are determined, that is, the module 1 and the module 4, and the modules 1 and 4 are sequentially Task 3 that needs to be processed currently is called until all task calls in all modules in the A page are completed.
  • the module calling sequence may be set according to a page, or may be set according to a task. The following description will be respectively made.
  • the module calling sequence corresponding to the task that needs to be processed is determined.
  • the module calling order of task 1 is module 1, module 2, module 3, and module 4; and for task 2, the module calling sequence may be set to module 2.
  • Module 1, Module 3, and Module 4 are more reasonable. Therefore, when determining the module calling sequence, it is necessary to determine the correspondence between the task and the module calling sequence. If it is task 1, the module calling sequence is module 1, module 2, module 3, module 4; if it is task 2, the module calling sequence It is module 2, module 1, module 3, and module 4.
  • the module calling sequence corresponding to the page currently needed to be processed is determined.
  • the module calling order of the A page is module 1, module 2, module 3, and module 4; and in the B page, it may be more reasonable to set the module calling order to module 2, module 1, module 3, and module 4. Therefore, when determining the module calling sequence, it is necessary to determine the correspondence between the page and the module calling sequence. If it is the A page, the module calling order is module 1, module 2, module 3, module 4; if it is the B page, the module calling sequence It is module 2, module 1, module 3, and module 4.
  • module calling sequences can be set for different tasks and pages as needed.
  • module calling order of task 1 in the A page is module 1, module 2, module 3, and module 4; and task 2 in the A page may set the module calling order to module 2, module 1, module 3, and module. 4 is more reasonable. Therefore, when determining the module calling sequence, it is necessary to determine the correspondence between the task and the page and the calling order of the module. If the task 1 in the A page, the calling order of the module is module 1, module 2, module 3, module 4; In task 2, the module calling sequence is module 2, module 1, module 3, and module 4.
  • the method for determining the order in which the modules are called is not limited to the above-described manners determined according to tasks and/or pages, and other methods capable of determining the order in which the modules are called are also applicable to the method of the present application.
  • all the tasks corresponding to the modules in the page may be stored in the buffer area before the step 101; correspondingly, in step 101, the page is determined according to the tasks stored in the buffer area.
  • Each task for each module may be stored in the buffer area before the step 101; correspondingly, in step 101, the page is determined according to the tasks stored in the buffer area.
  • the preset A page includes four modules, module 1, module 2, module 3, and module 4; wherein module 1 includes task 1, task 2, and task 3; Module 2 contains Task 1, Task 2; Module 3 contains Task 2; Module 4 contains Task 2, Task 3.
  • module 1 includes task 1, task 2, and task 3
  • module 2 contains Task 1, Task 2
  • Module 3 contains Task 2
  • Module 4 contains Task 2, Task 3.
  • the above four modules and corresponding tasks need to be stored in the buffer area, so that each task of each module in the page can be determined according to the tasks stored in the buffer area.
  • the logical processing of the broadcast event between different modules can be completed according to the set task processing sequence.
  • the priority of the listening task in the listening module is higher than the priority of the broadcast task in the broadcast module.
  • the page contains a broadcast event
  • the page will include a listener module for listening to the event and a broadcast module for the broadcast event.
  • the listener module needs to listen to the monitor module and the broadcast module.
  • the priority of the task is set to be higher than the priority of the broadcast task in the broadcast module, so that the broadcast module has started to perform the monitoring task before the broadcast module performs the broadcast task, and is ready to listen to the event transmitted by the broadcast module.
  • the listening task in the monitoring module is task 2
  • the broadcast task in the broadcast module is the task after task 2, and is set to task 3.
  • the embodiment of the present application can be implemented by using the order configuration item and the method name in the above example, and can also be implemented by other solutions. As long as the page module loading can be implemented, the embodiment of the present application can be used.
  • Methods for example, the order configuration item is not an array of method names but a map.
  • the content may not be a method name, but a regular expression that identifies the method.
  • the order configuration is not a method but a module, or a regular expression that matches the module identifier. And so on.
  • the execution process of the foregoing parts of the embodiment of the present application is implemented on the website side, but the specific execution body may be implemented by one server, or the functions may be distributed in multiple servers, as long as the method in the embodiment of the present application can be implemented. Yes, the type or structure of the specific execution subject is not limited.
  • the overall flow chart of the method for loading a page module provided by the embodiment of the present application is as follows. In the following, assuming that the module calling sequence is determined according to a corresponding relationship between a preset task and a module calling sequence, the overall process includes:
  • Step 301 Store all tasks corresponding to each module in the page into a buffer area.
  • Step 302 Determine each task of each module in the page according to the task stored in the cache area.
  • Step 303 Determine a task processing sequence corresponding to the page according to a correspondence between the preset page and the task processing sequence.
  • Step 304 Determine, according to the determined task processing sequence, that the task with the highest priority that is currently unprocessed is the task that needs to be processed currently;
  • Step 305 Determine, according to a correspondence between a preset page and a module calling sequence, a module calling sequence corresponding to the page;
  • Step 306 In accordance with the determined module calling sequence, sequentially call the task currently needed to be processed in the module;
  • Step 307 Determine whether there are any unprocessed tasks in all the tasks. If yes, execute step 304. Otherwise, determine that the page loading is completed.
  • FIG. 4 it is a schematic flowchart of an overall process of loading a page module in a browser according to an embodiment of the present application. Assume that the page includes 1 to N, N modules, each of which corresponds to task 1, task 2, and task 3.
  • the device of the present application further provides a device for loading a page module.
  • the principle of solving the problem is similar to the method for loading a page module in the embodiment of the present application. Therefore, the implementation of the device can refer to the implementation of the method. , the repetition will not be repeated.
  • the device for loading a page module provided by the embodiment of the present application includes: a first determining module 501, a second determining module 502, and a processing module 503.
  • a first determining module 501 configured to determine each task of each module in the page, where the task is an operation corresponding to the loading module;
  • the second determining module 502 is configured to determine, according to the set task processing sequence, that the task with the highest priority that is currently unprocessed is the task that needs to be processed currently;
  • the processing module 503 is configured to sequentially process the current needs of the module according to the set module calling sequence. The call is made, and the second determining module 502 is triggered to perform the step of determining that the currently unprocessed task with the highest priority is the task currently to be processed until all tasks of all modules in the page are called.
  • the embodiment of the present application determines each task of each module in the page, and sequentially invokes the tasks of the same task processing order in each module in the page according to the set module calling sequence. Since the module calling sequence and the task processing order can be set as needed, when the module or the task in the order of priority is required to be executed, the task priority of the corresponding task in the module can be set to a higher priority. There is no need to add additional delay calling functions to the programs corresponding to other modules, so the connection between the modules is not increased, and the coupling between the modules is reduced.
  • the second determining module 502 is further configured to determine a task processing sequence according to the following manner:
  • the task processing sequence corresponding to the page is determined according to the correspondence between the preset page and the task processing order.
  • the second determining module 502 can set different task processing sequences for tasks in different pages according to needs, and needs to determine the task processing order corresponding to the current page according to the correspondence between the page and the task processing order. For example, suppose the task processing order of the A page is Task 1, Task 2, and Task 3; and in the B page, it may be more reasonable to set the task processing order to Task 2, Task 1, and Task 3. Therefore, when determining the task processing order, it is necessary to determine the correspondence between the page and the task processing order. If the page is A, the task processing order is task 1, task 2, task 3; if it is the B page, the task processing order is task 2 , task 1, task 3.
  • the task with the highest priority that is currently unprocessed is the task that needs to be processed currently; or the example is as shown in FIG. 2, and the page is the A page, and the task processing order corresponding to the A page is task 1, task 2 Task 3.
  • module 1 includes task 1, task 2, task 3; module 2 includes task 1, task 2; module 3 includes task 2; and module 4 includes task 2, task 3. Therefore, according to the set task processing order, the task 1, the task 2, and the task 3 determine that the task 1 with the highest priority that is currently unprocessed is the task that needs to be processed currently.
  • the module calling sequence of a certain page may be preset, and the module calling sequence corresponding to the currently required task may be determined according to different tasks or the correspondence between the page and the module calling sequence.
  • processing module 503 is further configured to determine a module calling sequence according to the following manner:
  • the module calling sequence may be set according to a page, or may be set according to a task.
  • the processing module 503 determines, according to the correspondence between the preset task and the module calling sequence, the module calling sequence corresponding to the task that needs to be processed.
  • the module calling order of task 1 is module 1, module 2, module 3, and module 4; and for task 2, the module calling sequence may be set to module 2.
  • Module 1, Module 3, and Module 4 are more reasonable. Therefore, when determining the module calling sequence, it is necessary to determine the correspondence between the task and the module calling sequence. If it is task 1, the module calling sequence is module 1, module 2, module 3, module 4; if it is task 2, the module calling sequence It is module 2, module 1, module 3, and module 4.
  • the module calling sequence corresponding to the page currently needed to be processed is determined.
  • the processing module 503 can set different module calling sequences for different pages as needed.
  • the module calling order of the A page is module 1, module 2, module 3, and module 4; and in the B page, it may be more reasonable to set the module calling order to module 2, module 1, module 3, and module 4. Therefore, when determining the module calling sequence, it is necessary to determine the correspondence between the page and the module calling sequence. If it is the A page, the module calling order is module 1, module 2, module 3, module 4; if it is the B page, the module calling sequence It is module 2, module 1, module 3, and module 4.
  • the processing module 503 can set different module calling sequences for different tasks and pages as needed.
  • module calling order of task 1 in the A page is module 1, module 2, module 3, and module 4; and task 2 in the A page may set the module calling order to module 2, module 1, module 3, and module. 4 is more reasonable. Therefore, when determining the module calling sequence, it is necessary to determine the correspondence between the task and the page and the calling order of the module. If the task 1 in the A page, the calling order of the module is module 1, module 2, module 3, module 4; In task 2, the module calling sequence is module 2, module 1, module 3, and module 4.
  • the method for determining the order in which the modules are called is not limited to the manner determined according to the preset tasks and/or pages, and other methods capable of determining the order of calling the modules are also applicable to the method of the present application.
  • the first determining module 501 is further configured to:
  • each module in the embodiment of the present application corresponds to at least one init method.
  • a module includes an ad slot that needs to be rendered, display binding interaction events (such as an image carousel event, and an event that automatically pops up a drop-down box to promptly input content when inputting content in the input box), and an animation that needs to be rendered.
  • display binding interaction events such as an image carousel event, and an event that automatically pops up a drop-down box to promptly input content when inputting content in the input box
  • an animation that needs to be rendered.
  • multiple operations such as rendered audio.
  • the first determining module 501 is further configured to:
  • each task of each module in the page Before determining each task of each module in the page, all the tasks corresponding to each module in the page are stored into the buffer area; and each task of each module in the page is determined according to the tasks stored in the buffer area.
  • the preset A page includes four modules, module 1, module 2, module 3, and module 4; wherein module 1 includes task 1, task 2, and task 3; Module 2 contains Task 1, Task 2; Module 3 contains Task 2; Module 4 contains Task 2, Task 3.
  • module 1 includes task 1, task 2, and task 3
  • module 2 contains Task 1, Task 2
  • Module 3 contains Task 2
  • Module 4 contains Task 2, Task 3.
  • the above four modules and corresponding tasks need to be stored in the buffer area, so that each task of each module in the page can be determined according to the tasks stored in the buffer area.
  • processing module 503 is further configured to:
  • the processing module 503 needs to determine the modules of all the modules of the page that contain the tasks that need to be processed at present, and remove the modules that do not include the currently required processing tasks, and sequentially process the current needs in the remaining modules (ie, the determined modules). The task is called.
  • module 1 includes task 1, task 2, task 3; module 2 includes task 1, task 2; module 3 includes task 2; and module 4 includes task 2, task 3 . Therefore, according to the set task processing order for task 1, task 2, task 3, the task with the highest priority that is currently unprocessed is determined. 1 is the task that needs to be processed, and it is determined that the four modules of the A page include the module of the task 1 that needs to be processed currently, that is, the module 1 and the module 2, and sequentially call the task 1 that needs to be processed in the modules 1 and 2 in sequence. .
  • the four modules of the A page contain the modules of the task 2 that need to be processed currently, namely, the module 1, the module 2, the module 3, and the module 4, and sequentially the modules 1, 2, Calls 2 of 3 and 4 that need to be processed currently.
  • the priority of the listening task in the listening module is higher than the priority of the broadcast task in the broadcast module.
  • the page will include a listener module for listening to the event and a broadcast module for the broadcast event.
  • the listener module needs to listen to the monitor module and the broadcast module.
  • the priority of the task is set to be higher than the priority of the broadcast task in the broadcast module, so that the broadcast module has started to perform the monitoring task before the broadcast module performs the broadcast task, and is ready to listen to the event transmitted by the broadcast module. For example, if the listening task in the monitoring module is task 2, the broadcast task in the broadcast module is the task after task 2, and is set to task 3.
  • the embodiment of the present application determines each task of each module in the page, and sequentially invokes the tasks of the same task processing order in each module in the page according to the set module calling sequence. Since the module calling sequence and the task processing order can be set as needed, when the module or the task in the order of priority is required to be executed, the task priority of the corresponding task in the module can be set to a higher priority. There is no need to add additional delay calling functions to the programs corresponding to other modules, so the connection between the modules is not increased, and the coupling between the modules is reduced.
  • the application can also be implemented in hardware and/or software (including firmware, resident software, microcode, etc.). Still further, the application can take the form of a computer program product on a computer usable or computer readable storage medium having computer usable or computer readable program code embodied in a medium for use by an instruction execution system or Used in conjunction with the instruction execution system.
  • a computer usable or computer readable medium can be any medium that can contain, store, communicate, communicate, or transport the program to be executed by the instruction. Used by a system, device, or device, or in conjunction with an instruction execution system, device, or device.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Computer And Data Communications (AREA)

Abstract

一种加载页面模块的方法和设备,该方法包括:确定页面中每个模块的每个任务对应的任务类型,根据设定的任务类型处理顺序,确定当前未处理的优先级最高的任务类型为当前需要处理的任务类型;按照设定的模块调用顺序,依次对每个模块中的当前需要处理的任务类型对应的任务进行调用,并返回确定当前未处理的优先级最高的任务类型的步骤,直到调用完页面中所有模块的所有任务。该方法可以解决现有技术中页面模块的加载方式是逐一调用每个模块,若要优先执行顺序靠后的模块,需要在其它模块对应的程序中加入延迟调用函数语句,因而各个模块之间联系会变紧密,进而造成各个模块之间耦合性较强的问题。

Description

一种加载页面模块的方法和设备
本申请要求2015年03月27日递交的申请号为201510142348.9、发明名称为“一种加载页面模块的方法和设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及网络技术领域,特别涉及一种加载页面模块的方法和设备。
背景技术
如今前端的JS(Java Script,脚本语言)越来越追求模块化,模块与模块之间尽可能的解耦,因此也就诞生了AMD(Asynchronous Module Definition,异步模块定义),CMD(Common Module Definition,常见的模块定义)等规范的模块化JS写法。每个模块的JS只负责这一个小模块的交互,渲染等操作。
一般来说,每个模块有一个入口的方法(例如用变量init方法表示入口的方法),当页面在文件准备就绪以后,框架会去逐一调用每个模块的init方法,以完成所有模块的渲染,注册交互事件等。然而,在有的页面中多个模块的执行顺序固定,执行顺序靠后的模块会比较晚才能渲染出来,有时为了使其优先执行,只能在其它模块的init方法里加入延迟调用函数语句,使其它模块延后执行,这种方法会使模块之间的耦合度较高,进而造成模块的执行效率较低。
综上所述,目前页面模块的加载方式是逐一调用每个模块,若要优先执行顺序靠后的模块,需要在其它模块对应的程序中加入延迟调用函数,因而各个模块之间联系会变紧密,进而造成各个模块之间耦合性较强。
发明内容
本申请实施例提供的一种加载页面模块的方法和设备,用以解决现有技术中存在的页面模块的加载方式是逐一调用每个模块,若要优先执行顺序靠后的模块,需要在其它模块对应的程序中加入延迟调用函数语句,但延迟调用函数会造成各个模块之间的耦合度较高的问题。
一方面,本申请实施例提供的一种加载页面模块的方法,该方法包括:
确定页面中每个模块的每个任务,其中所述任务是加载模块所对应的操作;
根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
按照设定的模块调用顺序,依次对模块中的所述当前需要处理的任务进行调用,并返回确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完所述页面中所有模块的所有任务。
本申请实施例确定页面中每个模块的每个任务,并根据设定的模块调用顺序,依次对页面中各个模块中的同一任务处理顺序的任务进行调用。由于能够根据需要设定模块调用顺序和任务处理顺序,从而在需要优先执行顺序靠后的模块或者任务时,可以通过将该模块中对应任务的任务优先级设定为较高的优先级实现,而无需在其它模块对应的程序中增加额外的延迟调用函数,因而不会增加各个模块之间的联系,进而使各个模块之间的耦合性降低。
可选的,根据下列方式确定任务处理顺序:
根据预设页面与任务处理顺序的对应关系,确定所述页面对应的任务处理顺序。
由于本申请实施例可以通过不同的方式确定任务处理顺序,因而能够满足更多不同处理顺序的需求,从而增加了加载页面模块的方式的多样性。
可选的,根据下列方式确定模块调用顺序:
根据预设的任务与模块调用顺序的对应关系,确定所述当前需要处理的任务对应的模块调用顺序;和/或
根据预设页面与模块调用顺序的对应关系,确定所述页面对应的模块调用顺序。
由于本申请实施例可以通过不同的方式确定模块调用顺序,因而能够满足更多不同处理顺序的需求,从而增加了加载页面模块的方式的多样性。
可选的,确定页面中每个模块的每个任务之前,还包括:
针对一个模块,将该模块对应的需要同时执行的操作作为该模块的一个任务。
由于本申请实施例将每个模块分为多个任务,进而通过控制每个任务的处理顺序,满足不同的加载需求,从而增加了加载页面模块的方式的多样性。
可选的,确定页面中每个模块的每个任务之前,还包括:
将所述页面中的各个模块对应的所有任务存储到缓存区中;
确定页面中每个模块的每个任务,包括:
根据所述缓存区中存储的任务,确定所述页面中每个模块的每个任务。
由于将页面中所有模块的所有任务都存储到了缓存区,因而在页面加载时,可以提 高加载的速度。
可选的,确定当前未处理的优先级最高的任务为当前需要处理的任务之后,依次对模块中的所述当前需要处理的任务进行调用之前,还包括:
确定每个模块的所有任务中包含所述当前需要处理的任务的模块;
依次对模块中的所述当前需要处理的任务进行调用,包括:
依次对确定的模块中的所述当前需要处理的任务进行调用。
由于在确定出当前需要处理的任务之后,仅对页面中所有模块中包含所述当前需要处理的任务的模块进行调用,进而能够实现依次执行页面的不同模块中的相同类型的任务。
可选的,若所述页面包括用于监听事件的监听模块和用于广播事件的广播模块,则所述监听模块中监听任务的优先级,比所述广播模块中广播任务的优先级高。
由于可以预先设定模块调用顺序和任务处理顺序,因而可以仅通过设定执行广播事件的监听模块和广播模块的优先级顺序,就能实现页面中的广播事件。
另一方面,本申请实施例提供的一种加载页面模块的设备,该设备包括:
第一确定模块,用于确定页面中每个模块的每个任务,其中所述任务是加载模块所对应的操作;
第二确定模块,用于根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
处理模块,用于按照设定的模块调用顺序,依次对模块中的所述当前需要处理的任务进行调用,并触发第二确定模块执行确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完所述页面中所有模块的所有任务。
可选的,所述第二确定模块还用于,根据下列方式确定任务处理顺序:
根据预设页面与任务处理顺序的对应关系,确定所述页面对应的任务处理顺序。
可选的,所述处理模块还用于,根据下列方式确定模块调用顺序:
根据预设的任务与模块调用顺序的对应关系,确定所述当前需要处理的任务对应的模块调用顺序;和/或,根据预设页面与模块调用顺序的对应关系,确定所述页面对应的模块调用顺序。
可选的,所述第一确定模块还用于:
在确定页面中每个模块的每个任务之前,针对一个模块,将该模块对应的需要同时执行的操作作为该模块的一个任务。
可选的,所述第一确定模块还用于:
在确定页面中每个模块的每个任务之前,将所述页面中的各个模块对应的所有任务存储到缓存区中;并根据所述缓存区中存储的任务,确定所述页面中每个模块的每个任务。
可选的,所述处理模块还用于:
在确定当前未处理的优先级最高的任务为当前需要处理的任务之后,依次对模块中的所述当前需要处理的任务进行调用之前,确定每个模块的所有任务中包含所述当前需要处理的任务的模块;并依次对确定的模块中的所述当前需要处理的任务进行调用。
可选的,若所述页面包括用于监听事件的监听模块和用于广播事件的广播模块,则所述监听模块中监听任务的优先级,比所述广播模块中广播任务的优先级高。
附图说明
图1为本申请实施例提供的一种加载页面模块的方法;
图2为本申请实施例提供的页面模块分布示意图;
图3为本申请实施例提供的加载页面模块的方法的整体流程示意图;
图4为本申请实施例提供的在浏览器中加载页面模块的整体流程示意图;
图5为本申请实施例提供的一种加载页面模块的结构示意图。
具体实施方式
本申请实施例确定页面中每个模块的每个任务,并根据设定的模块调用顺序,依次对页面中各个模块中的同一任务处理顺序的任务进行调用。由于能够根据需要设定模块调用顺序和任务处理顺序,从而在需要优先执行顺序靠后的模块或者任务时,可以通过将该模块中对应任务的任务优先级设定为较高的优先级实现,而无需在其它模块对应的程序中增加额外的延迟调用函数,因而不会增加各个模块之间的联系,进而使各个模块之间的耦合性降低。
以下结合说明书附图对本申请的优选实施例进行说明,应当理解,此处所描述的优选实施例仅用于说明和解释本申请,并不用于限定本申请。并且在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
下面结合说明书附图对本申请实施例作进一步详细描述。
如图1所示,本申请实施例提供的一种加载页面模块的方法包括:
步骤101、确定页面中每个模块的每个任务,其中任务是加载模块所对应的操作;
步骤102、根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
步骤103、按照设定的模块调用顺序,依次对模块中的当前需要处理的任务进行调用,并返回确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完页面中所有模块的所有任务。
实施中,本申请实施例中涉及到的模块的划分、任务处理顺序的设定以及模块调用顺序的设定,都可以根据用户的实际需要进行设定。同时,有多种情况需要加载页面模块,比如用户需要打开浏览器打开网页时,或者是用户通过手机客户端打开网页时,采用模块化编程的实现形式,通过分别加载每个模块中的内容,进而展示出整个页面中的内容。
现有技术将页面中每个模块对应的所有操作作为一个init方法,也就是说,一个模块对应一个init方法。而在本申请实施例中,将页面中每个模块对应的需要同时执行的操作作为一个任务(即一个init方法)。也就说是,本申请实施例中的每个模块会对应至少一个init方法。
例如,假设针对页面中某一个模块,该模块中包括需要渲染的广告位,显示绑定交互事件(比如图片轮播事件,以及在输入框输入内容时自动弹出下拉框实时提示输入内容的事件等)、需要渲染的动画、以及渲染的音频等多个操作。
在现有技术中,在加载模块时同时加载该模块中的所有操作。而本申请实施例中,可以根据需要将该模块中需要同时执行的操作作为一个任务,且该模块中这些可以根据需要划分为多个任务。
例如,针对该页面的广告位和需要渲染的动画,根据实际需要两者要同时展现给用户,因而需要将渲染的广告位和需要渲染的动画同时执行,且该模块中其它的显示绑定交互事件和需要渲染的音频也需要同时展现给用户;因而可以将渲染广告位所对应的操作以及渲染动画所对应的操作作为一个任务,而将显示绑定交互事件所对应的操作以及渲染音频所对应的操作作为一个任务。
为了方便对本申请实施例进行说明,下面结合具体的页面划分的模块进行说明,如图2所示,为本申请实施例提供的页面模块分布示意图;图中虚线框表示首屏能够展示的页面范围,并将首屏的页面分为4个模块(即模块1、模块2、模块3和模块4)。本申请实施例仅以某一页面首页分为4个模块,且每个模块对应任务1、任务2、任务3三 个任务为例进行详细介绍,但并不代表是本申请实施例仅有这一种形式,其它划分不同的模块个数的页面也适用于本申请实施例的方法。
本申请实施例是将每个模块根据需要对应划分为多个任务,并且可以根据设定的任务执行顺序,以及调用各个模块的顺序,对模块中的各个任务进行相应处理。
可选的,根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务。
实施中,任务处理顺序有多种设定的方式,可以根据实际需要进行设定;比如,可以根据需要预先设定好任务的执行顺序。
例如,针对该页面的广告位,业务上希望这一块的数据最先加载完成,以获取更多的曝光和点击率,同时为了突出广告的内容,吸引用户眼球,该模块中相应的需要渲染的动画也需要优先执行;而将该模块中其它的显示绑定交互事件和需要渲染的音频不需要优先执行;因而在设定任务处理顺序时,可以设定需要优先执行的渲染广告位和渲染动画所对应的任务的优先级,比不需要优先执行的显示绑定交互事件进而渲染音频所对应的任务的优先级高。
又例如,在实例化的时候可以配置参数为:
order:[‘init1’,’init2’,’init3’]
其中,order是一个数组,它规定了先把所有模块的init1(即任务1)执行完成,再执行所有模块的init2(即任务2),init3(即任务3)。此处order的指定可以形成一个规范,比如任务1是任务处理顺序的优先级最高的任务,不能随便使用,可以将最需要优先执行的任务放在任务1中。
例如,可以按照场景的不同,以及用户的实际需要,将页面中每个模块对应的需要同时执行的操作作为一个任务,并且根据需要设定所有任务的任务处理顺序,假设某页面包括三个任务,其预设的任务处理顺序的优先级从高到低分别为任务1、任务2、任务3。其中,每个任务中包含的具体操作,可以根据用户需要进行设定,下面假设每个任务中包含的操作。
任务1:可以根据需要将页面首屏的某个模块中需要JS执行才能渲染出的内容所对应的渲染的相关操作;业务上需要优先渲染出的,比如渲染广告位所对应的相关操作等作为优先级最高的任务。
任务2:可以根据需要将首屏中普通模块的初始化方法(如非渲染的操作)等,比如显示绑定交互事件所对应的相关操作作为优先级第二的任务。
任务3:可以根据需要将非首屏模块的初始化方法所对应的相关操作,比如非首屏模块中渲染广告位所对应的相关操作,或者是非首屏模块中显示绑定交互事件所对应的相关操作等作为优先级第三的任务。
上述任务1、任务2、任务3的举例仅是为了方便说明本申请的实施例,但本申请实施例并不仅限于适用于上述举例中的场景,其它的与加载页面相关的场景也适用本申请的方法。
下面的说明举例过程中,仍以上述任务1、任务2、任务3以及页面划分为4个模块为例进行说明,为了方便说明,以下都以任务1代表优先级最高的任务,任务2代表优先级第二的任务,任务3代表优先级第三的任务;而四个模块分别用模块1、模块2、模块3和模块4表示。
除了可以预先设定某一页面的任务处理顺序外,还可以根据需要将不同的页面设定为对应不同的任务处理顺序。可选的,根据下列方式确定任务处理顺序:根据预设页面与任务处理顺序的对应关系,确定页面对应的任务处理顺序。
也就是说,可以根据需要对不同的页面中的任务设定不同的任务处理顺序,需要根据页面与任务处理顺序的对应关系,确定当前页面对应的任务处理顺序。例如,假定A页面的任务处理顺序为任务1、任务2、任务3;而B页面中,可能将任务处理顺序设定为任务2、任务1、任务3更加合理。因而,在确定任务处理顺序时,需要确定该页面与任务处理顺序的对应关系,若是A页面,则任务处理顺序为任务1、任务2、任务3;若是B页面,则任务处理顺序为任务2、任务1、任务3。
实施中,要先确定当前未处理的优先级最高的任务为当前需要处理的任务;还是以如图2为例,且该页面为A页面,A页面对应的任务处理顺序为任务1、任务2、任务3。其中,假设模块1包含任务1、任务2、任务3;模块2包含任务1、任务2;模块3包含任务2;模块4包含任务2、任务3。因而,根据设定的任务处理顺序为任务1、任务2、任务3,确定出当前未处理的优先级最高的任务1为当前需要处理的任务。
其中,确定任务处理顺序的方法不仅限于上述根据页面确定的方式,其它能够确定任务处理顺序的方法也适用于本申请的方法。
在确定出当前需要处理的任务后,对当前需要处理的任务进行处理时,需要剔除掉不包含当前需要处理任务的模块。具体的,在步骤102之后,步骤103之前,确定每个模块的所有任务中包含当前需要处理的任务的模块;依次对确定的模块中的当前需要处理的任务进行调用。
也就是说,首先要确定出页面的所有模块中包含当前需要处理的任务的模块,剔除掉不包含当前需要处理任务的模块,依次对剩余模块(即确定的模块)中的当前需要处理的任务进行调用。
接着以图2中4个模块的A页面为例,假设模块1包含任务1、任务2、任务3;模块2包含任务1、任务2;模块3包含任务2;模块4包含任务2、任务3。因而,根据设定的任务处理顺序为任务1、任务2、任务3,确定出当前未处理的优先级最高的任务1为当前需要处理的任务后,确定A页面的4个模块中包含当前需要处理的任务1的模块,即模块1和模块2,依次对模块1和2中的当前需要处理的任务1进行调用。
若假设当前需要处理的任务为任务2,则确定A页面的4个模块中包含当前需要处理的任务2的模块,即模块1、模块2、模块3和模块4,依次对模块1、2、3和4中的当前需要处理的任务2进行调用。
在依次对模块中的当前需要处理的任务进行调用之后,判断剩余的任务中优先级最高的任务并进行调用。可选的,按照设定的模块调用顺序,依次对模块中的当前需要处理的任务进行调用,并返回确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完页面中所有模块的所有任务。
实施中,在按照设定的模块调用顺序,依次对模块中的当前需要处理的任务进行调用完成之后,判断剩余的任务中优先级最高的任务为当前需要处理的任务,并根据前述方法对确定的当前需要处理的任务进行调用,直到调用完页面中所有模块的所有任务。
例如,以上述图2中4个模块的A页面为例,根据设定的任务处理顺序为任务1、任务2、任务3,确定出当前未处理的优先级最高的任务1为当前需要处理的任务后,确定A页面的4个模块中包含当前需要处理的任务1的模块,即模块1和模块2,依次对模块1和2中的当前需要处理的任务1进行调用。继续判断当前未处理的优先级最高的任务2为当前需要处理的任务,确定A页面的4个模块中包含当前需要处理的任务2的模块,即模块1、模块2、模块3和模块4,依次对模块1、2、3和4中的当前需要处理的任务2进行调用。判断当前未处理的优先级最高的任务3为当前需要处理的任务,确定A页面的4个模块中包含当前需要处理的任务3的模块,即模块1和模块4,依次对模块1和4中的当前需要处理的任务3进行调用,直到A页面中所有模块中的所有任务调用完成。
本申请实施例中模块调用顺序可以依据页面进行设定,也可以依据任务进行设定。下面分别进行说明。
一、根据预设的任务,确定模块调用顺序。
具体的,根据预设的任务与模块调用顺序的对应关系,确定当前需要处理的任务对应的模块调用顺序。
也就是说,可以根据需要对不同的任务设定不同的模块调用顺序。
以上述图2中4个模块的A页面为例,假定任务1的模块调用顺序为模块1、模块2、模块3、模块4;而针对任务2,可能将模块调用顺序设定为模块2、模块1、模块3、模块4更加合理。因而,在确定模块调用顺序时,需要确定该任务与模块调用顺序的对应关系,若是任务1,则模块调用顺序为模块1、模块2、模块3、模块4;若是任务2,则模块调用顺序为模块2、模块1、模块3、模块4。
二、根据预设页面,确定模块调用顺序。
具体的,根据预设的页面与模块调用顺序的对应关系,确定当前需要处理的页面对应的模块调用顺序。
也就是说,可以根据需要对不同的页面设定不同的模块调用顺序。
例如,假定A页面的模块调用顺序为模块1、模块2、模块3、模块4;而B页面中,可能将模块调用顺序设定为模块2、模块1、模块3、模块4更加合理。因而,在确定模块调用顺序时,需要确定该页面与模块调用顺序的对应关系,若是A页面,则模块调用顺序为模块1、模块2、模块3、模块4;若是B页面,则模块调用顺序为模块2、模块1、模块3、模块4。
三、根据预设的任务和页面,确定模块调用顺序。
也就是说,可以根据需要对不同的任务和页面设定不同的模块调用顺序。
例如,假定A页面中任务1的模块调用顺序为模块1、模块2、模块3、模块4;而A页面中任务2,可能将模块调用顺序设定为模块2、模块1、模块3、模块4更加合理。因而,在确定模块调用顺序时,需要确定任务和页面,与模块调用顺序的对应关系,若是A页面中任务1,则模块调用顺序为模块1、模块2、模块3、模块4;若是A页面中任务2,则模块调用顺序为模块2、模块1、模块3、模块4。
其中,确定模块调用顺序的方法不仅限于上述根据任务和/或页面确定的方式,其它能够确定模块调用顺序的方法也适用于本申请的方法。
可选的,为了提高页面加载速度,可以在步骤101之前,将页面中的各个模块对应的所有任务存储到缓存区中;相应的,步骤101中,根据缓存区中存储的任务,确定页面中每个模块的每个任务。
实施中,在浏览器打开后,加载模块时,将页面中预先设定的各个模块对应的所有任务存储到缓存区中,以便在执行步骤101时,能够根据缓存区中存储的任务,确定页面中每个模块的每个任务。
例如,以上述图2中4个模块的A页面为例,预设的A页面包含4个模块,模块1、模块2、模块3、模块4;其中,模块1包含任务1、任务2、任务3;模块2包含任务1、任务2;模块3包含任务2;模块4包含任务2、任务3。则在步骤101之前,需要将上述4个模块和对应的任务存储到缓存区中,以便能够根据缓存区中存储的任务,确定页面中每个模块的每个任务。
实施中,如果页面中包含广播事件,则可以根据设定任务处理顺序,完成不同模块之间的广播事件的逻辑处理。
可选的,若页面包括用于监听事件的监听模块和用于广播事件的广播模块,则监听模块中监听任务的优先级,比广播模块中广播任务的优先级高。
若页面中包含广播事件,则页面中会相应的包含用于监听事件的监听模块和用于广播事件的广播模块,则无论监听模块和广播模块的模块调用顺序如何,都需要将监听模块中监听任务的优先级设定为比广播模块中广播任务的优先级高,以便广播模块在执行广播任务之前,监听模块已经开始执行监听任务,能够准备监听到广播模块的发送的事件。
例如,若监听模块中监听任务的为任务2,则广播模块中的广播任务为任务2以后的任务,如设定为任务3。
本申请实施例在实施时,可以通过上述举例中的order配置项和方法名来实现,同时也可以用其它的方案实现,只要是能够实现页面模块加载的方案,都是可以使用本申请实施例的方法。比如,order配置项不是一个方法名的数组而是一个map,内容也可以不是方法名,而是标识方法的正则表达式等;order配置的不是方法而是模块,或者是匹配模块标识的正则表达式等。
本申请实施例上述各部分的执行过程都在网站侧实现,但是具体执行主体可以由一个服务器实现,也可以将各功能分布在多个服务器实现,只要是能够实现本申请实施例中的方法即可,并不限定具体的执行主体的类型或者是结构。
如图3所示,为本申请实施例提供的加载页面模块的方法的整体流程示意图,其中,假设根据预设的任务与模块调用顺序的对应关系,确定模块调用顺序,则该整体流程包括:
步骤301、将页面中的各个模块对应的所有任务存储到缓存区中;
步骤302、根据缓存区中存储的任务,确定页面中每个模块的每个任务;
步骤303、根据预设页面与任务处理顺序的对应关系,确定页面对应的任务处理顺序;
步骤304、根据确定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
步骤305、根据预设的页面与模块调用顺序的对应关系,确定页面对应的模块调用顺序;
步骤306、按照确定的模块调用顺序,依次对模块中的当前需要处理的任务进行调用;
步骤307、判断所有任务中是否还有未处理的任务,若是,则执行步骤304,否则,确定页面加载完成。
为了更加充分的说明本申请实施例中加载页面模块的方法,下面以浏览器加载页面模块为例,对上述方法的整体流程进行详细说明。如图4所示,为本申请实施例提供的在浏览器中加载页面模块的整体流程示意图。假定页面包括1到N,N个模块,每个模块都对应任务1、任务2和任务3三个任务。打开浏览器,开始准备加载需要打开的页面中的各个模块,即加载模块1、模块2、模块3、一直到模块N,以及每个模块对应的任务,其中N为正整数;并将所有模块以及对应的所有任务都保存到该缓存区中;文件准备就绪后,开始从缓存器中依次调用N个模块中的任务1,并依次调用N个模块中的任务2,以及依次调用N个模块中的任务3,直到执行完所有N个模块中的所有任务。
基于同一发明构思,本申请实施例中还提供了一种加载页面模块的设备,由于该设备解决问题的原理与本申请实施例加载页面模块的方法相似,因此该设备的实施可以参见方法的实施,重复之处不再赘述。
如图5所示,本申请实施例提供的加载页面模块的设备包括:第一确定模块501、第二确定模块502、处理模块503。
第一确定模块501,用于确定页面中每个模块的每个任务,其中任务是加载模块所对应的操作;
第二确定模块502,用于根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
处理模块503,用于按照设定的模块调用顺序,依次对模块中的当前需要处理的任 务进行调用,并触发第二确定模块502执行确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完页面中所有模块的所有任务。
本申请实施例确定页面中每个模块的每个任务,并根据设定的模块调用顺序,依次对页面中各个模块中的同一任务处理顺序的任务进行调用。由于能够根据需要设定模块调用顺序和任务处理顺序,从而在需要优先执行顺序靠后的模块或者任务时,可以通过将该模块中对应任务的任务优先级设定为较高的优先级实现,而无需在其它模块对应的程序中增加额外的延迟调用函数,因而不会增加各个模块之间的联系,进而使各个模块之间的耦合性降低。
可选的,第二确定模块502还用于,根据下列方式确定任务处理顺序:
根据预设页面与任务处理顺序的对应关系,确定页面对应的任务处理顺序。
也就是说,第二确定模块502可以根据需要对不同的页面中的任务设定不同的任务处理顺序,需要根据页面与任务处理顺序的对应关系,确定当前页面对应的任务处理顺序。例如,假定A页面的任务处理顺序为任务1、任务2、任务3;而B页面中,可能将任务处理顺序设定为任务2、任务1、任务3更加合理。因而,在确定任务处理顺序时,需要确定该页面与任务处理顺序的对应关系,若是A页面,则任务处理顺序为任务1、任务2、任务3;若是B页面,则任务处理顺序为任务2、任务1、任务3。
实施中,要确定当前未处理的优先级最高的任务为当前需要处理的任务;还是以如图2为例,且该页面为A页面,A页面对应的任务处理顺序为任务1、任务2、任务3。其中,假设模块1包含任务1、任务2、任务3;模块2包含任务1、任务2;模块3包含任务2;模块4包含任务2、任务3。因而,根据设定的任务处理顺序为任务1、任务2、任务3,确定出当前未处理的优先级最高的任务1为当前需要处理的任务。
针对模块调用顺序,除了上述可以预先设定某一页面的模块调用顺序外,还可以根据不同的任务或者是页面与模块调用顺序的对应关系,确定当前需要处理的任务对应的模块调用顺序。
可选的,处理模块503还用于,根据下列方式确定模块调用顺序:
根据预设的任务与模块调用顺序的对应关系,确定当前需要处理的任务对应的模块调用顺序;和/或,根据预设页面与模块调用顺序的对应关系,确定页面对应的模块调用顺序。
本申请实施例中模块调用顺序可以依据页面进行设定,也可以依据任务进行设定。
一、根据预设的任务,确定模块调用顺序。
具体的,处理模块503根据预设的任务与模块调用顺序的对应关系,确定当前需要处理的任务对应的模块调用顺序。
也就是说,可以根据需要对不同的任务设定不同的模块调用顺序。
以上述图2中4个模块的A页面为例,假定任务1的模块调用顺序为模块1、模块2、模块3、模块4;而针对任务2,可能将模块调用顺序设定为模块2、模块1、模块3、模块4更加合理。因而,在确定模块调用顺序时,需要确定该任务与模块调用顺序的对应关系,若是任务1,则模块调用顺序为模块1、模块2、模块3、模块4;若是任务2,则模块调用顺序为模块2、模块1、模块3、模块4。
二、根据预设页面,确定模块调用顺序。
具体的,根据预设的页面与模块调用顺序的对应关系,确定当前需要处理的页面对应的模块调用顺序。
也就是说,处理模块503可以根据需要对不同的页面设定不同的模块调用顺序。
例如,假定A页面的模块调用顺序为模块1、模块2、模块3、模块4;而B页面中,可能将模块调用顺序设定为模块2、模块1、模块3、模块4更加合理。因而,在确定模块调用顺序时,需要确定该页面与模块调用顺序的对应关系,若是A页面,则模块调用顺序为模块1、模块2、模块3、模块4;若是B页面,则模块调用顺序为模块2、模块1、模块3、模块4。
三、根据预设的任务和页面,确定模块调用顺序。
也就是说,处理模块503可以根据需要对不同的任务和页面设定不同的模块调用顺序。
例如,假定A页面中任务1的模块调用顺序为模块1、模块2、模块3、模块4;而A页面中任务2,可能将模块调用顺序设定为模块2、模块1、模块3、模块4更加合理。因而,在确定模块调用顺序时,需要确定任务和页面,与模块调用顺序的对应关系,若是A页面中任务1,则模块调用顺序为模块1、模块2、模块3、模块4;若是A页面中任务2,则模块调用顺序为模块2、模块1、模块3、模块4。
其中,确定模块调用顺序的方法不仅限于上述根据预设的任务和/或页面来确定的方式,其它能够确定模块调用顺序的方法也适用于本申请的方法。
可选的,第一确定模块501还用于:
在确定页面中每个模块的每个任务之前,针对一个模块,将该模块对应的需要同时执行的操作作为该模块的一个任务。
也就说是,本申请实施例中的每个模块会对应至少一个init方法。例如,假设某个模块中包括需要渲染的广告位,显示绑定交互事件(比如图片轮播事件,以及在输入框输入内容时自动弹出下拉框实时提示输入内容的事件等)、需要渲染的动画、以及渲染的音频等多个操作。
假设需要将渲染的广告位和需要渲染的动画同时执行,需要将显示绑定交互事件和需要渲染的音频同时执行,则将渲染广告位所对应的操作以及渲染动画所对应的操作作为一个任务,而将显示绑定交互事件所对应的操作以及渲染音频所对应的操作作为一个任务。
可选的,第一确定模块501还用于:
在确定页面中每个模块的每个任务之前,将页面中的各个模块对应的所有任务存储到缓存区中;并根据缓存区中存储的任务,确定页面中每个模块的每个任务。
实施中,在浏览器打开后,加载模块时,将页面中预先设定的各个模块对应的所有任务存储到缓存区中,以便在执行步骤101时,能够根据缓存区中存储的任务,确定页面中每个模块的每个任务。
例如,以上述图2中4个模块的A页面为例,预设的A页面包含4个模块,模块1、模块2、模块3、模块4;其中,模块1包含任务1、任务2、任务3;模块2包含任务1、任务2;模块3包含任务2;模块4包含任务2、任务3。则在步骤101之前,需要将上述4个模块和对应的任务存储到缓存区中,以便能够根据缓存区中存储的任务,确定页面中每个模块的每个任务。
在确定出当前需要处理的任务后,对当前需要处理的任务进行处理时,需要剔除掉不包含当前需要处理任务的模块。可选的,处理模块503还用于:
在确定当前未处理的优先级最高的任务为当前需要处理的任务之后,依次对模块中的当前需要处理的任务进行调用之前,确定每个模块的所有任务中包含当前需要处理的任务的模块;并依次对确定的模块中的当前需要处理的任务进行调用。
也就是说,处理模块503要确定出页面的所有模块中包含当前需要处理的任务的模块,剔除掉不包含当前需要处理任务的模块,依次对剩余模块(即确定的模块)中的当前需要处理的任务进行调用。
接着以图2中4个模块的A页面为例,假设模块1包含任务1、任务2、任务3;模块2包含任务1、任务2;模块3包含任务2;模块4包含任务2、任务3。因而,根据设定的任务处理顺序为任务1、任务2、任务3,确定出当前未处理的优先级最高的任务 1为当前需要处理的任务后,确定A页面的4个模块中包含当前需要处理的任务1的模块,即模块1和模块2,依次对模块1和2中的当前需要处理的任务1进行调用。
若假设当前需要处理的任务为任务2,则确定A页面的4个模块中包含当前需要处理的任务2的模块,即模块1、模块2、模块3和模块4,依次对模块1、2、3和4中的当前需要处理的任务2进行调用。
可选的,若页面包括用于监听事件的监听模块和用于广播事件的广播模块,则监听模块中监听任务的优先级,比广播模块中广播任务的优先级高。
若页面中包含广播事件,则页面中会相应的包含用于监听事件的监听模块和用于广播事件的广播模块,则无论监听模块和广播模块的模块调用顺序如何,都需要将监听模块中监听任务的优先级设定为比广播模块中广播任务的优先级高,以便广播模块在执行广播任务之前,监听模块已经开始执行监听任务,能够准备监听到广播模块的发送的事件。例如,若监听模块中监听任务的为任务2,则广播模块中的广播任务为任务2以后的任务,如设定为任务3。
从上述内容可以看出:本申请实施例确定页面中每个模块的每个任务,并根据设定的模块调用顺序,依次对页面中各个模块中的同一任务处理顺序的任务进行调用。由于能够根据需要设定模块调用顺序和任务处理顺序,从而在需要优先执行顺序靠后的模块或者任务时,可以通过将该模块中对应任务的任务优先级设定为较高的优先级实现,而无需在其它模块对应的程序中增加额外的延迟调用函数,因而不会增加各个模块之间的联系,进而使各个模块之间的耦合性降低。
以上参照示出根据本申请实施例的方法、装置(系统)和/或计算机程序产品的框图和/或流程图描述本申请。应理解,可以通过计算机程序指令来实现框图和/或流程图示图的一个块以及框图和/或流程图示图的块的组合。可以将这些计算机程序指令提供给通用计算机、专用计算机的处理器和/或其它可编程数据处理装置,以产生机器,使得经由计算机处理器和/或其它可编程数据处理装置执行的指令创建用于实现框图和/或流程图块中所指定的功能/动作的方法。
相应地,还可以用硬件和/或软件(包括固件、驻留软件、微码等)来实施本申请。更进一步地,本申请可以采取计算机可使用或计算机可读存储介质上的计算机程序产品的形式,其具有在介质中实现的计算机可使用或计算机可读程序代码,以由指令执行系统来使用或结合指令执行系统而使用。在本申请上下文中,计算机可使用或计算机可读介质可以是任意介质,其可以包含、存储、通信、传输、或传送程序,以由指令执行系 统、装置或设备使用,或结合指令执行系统、装置或设备使用。
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。

Claims (14)

  1. 一种加载页面模块的方法,其特征在于,该方法包括:
    确定页面中每个模块的每个任务,其中所述任务是加载模块所对应的操作;
    根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
    按照设定的模块调用顺序,依次对模块中的所述当前需要处理的任务进行调用,并返回确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完所述页面中所有模块的所有任务。
  2. 根据权利要求1所述的方法,其特征在于,根据下列方式确定任务处理顺序:
    根据预设页面与任务处理顺序的对应关系,确定所述页面对应的任务处理顺序。
  3. 根据权利要求1所述的方法,其特征在于,根据下列方式确定模块调用顺序:
    根据预设的任务与模块调用顺序的对应关系,确定所述当前需要处理的任务对应的模块调用顺序;和/或
    根据预设页面与模块调用顺序的对应关系,确定所述页面对应的模块调用顺序。
  4. 根据权利要求1所述的方法,其特征在于,确定页面中每个模块的每个任务之前,还包括:
    针对一个模块,将该模块对应的需要同时执行的操作作为该模块的一个任务。
  5. 根据权利要求1所述的方法,其特征在于,确定页面中每个模块的每个任务之前,还包括:
    将所述页面中的各个模块对应的所有任务存储到缓存区中;
    确定页面中每个模块的每个任务,包括:
    根据所述缓存区中存储的任务,确定所述页面中每个模块的每个任务。
  6. 根据权利要求1所述的方法,其特征在于,确定当前未处理的优先级最高的任务为当前需要处理的任务之后,依次对模块中的所述当前需要处理的任务进行调用之前,还包括:
    确定每个模块的所有任务中包含所述当前需要处理的任务的模块;
    依次对模块中的所述当前需要处理的任务进行调用,包括:
    依次对确定的模块中的所述当前需要处理的任务进行调用。
  7. 根据权利要求1~6任一所述的方法,其特征在于,若所述页面包括用于监听事件的监听模块和用于广播事件的广播模块,则所述监听模块中监听任务的优先级,比所 述广播模块中广播任务的优先级高。
  8. 一种加载页面模块的设备,其特征在于,该设备包括:
    第一确定模块,用于确定页面中每个模块的每个任务,其中所述任务是加载模块所对应的操作;
    第二确定模块,用于根据设定的任务处理顺序,确定当前未处理的优先级最高的任务为当前需要处理的任务;
    处理模块,用于按照设定的模块调用顺序,依次对模块中的所述当前需要处理的任务进行调用,并触发第二确定模块执行确定当前未处理的优先级最高的任务为当前需要处理的任务的步骤,直到调用完所述页面中所有模块的所有任务。
  9. 根据权利要求8所述的设备,其特征在于,所述第二确定模块还用于,根据下列方式确定任务处理顺序:
    根据预设页面与任务处理顺序的对应关系,确定所述页面对应的任务处理顺序。
  10. 根据权利要求8所述的设备,其特征在于,所述处理模块还用于,根据下列方式确定模块调用顺序:
    根据预设的任务与模块调用顺序的对应关系,确定所述当前需要处理的任务对应的模块调用顺序;和/或,根据预设页面与模块调用顺序的对应关系,确定所述页面对应的模块调用顺序。
  11. 根据权利要求8所述的设备,其特征在于,所述第一确定模块还用于:
    在确定页面中每个模块的每个任务之前,针对一个模块,将该模块对应的需要同时执行的操作作为该模块的一个任务。
  12. 根据权利要求8所述的设备,其特征在于,所述第一确定模块还用于:
    在确定页面中每个模块的每个任务之前,将所述页面中的各个模块对应的所有任务存储到缓存区中;并根据所述缓存区中存储的任务,确定所述页面中每个模块的每个任务。
  13. 根据权利要求8所述的设备,其特征在于,所述处理模块还用于:
    在确定当前未处理的优先级最高的任务为当前需要处理的任务之后,依次对模块中的所述当前需要处理的任务进行调用之前,确定每个模块的所有任务中包含所述当前需要处理的任务的模块;并依次对确定的模块中的所述当前需要处理的任务进行调用。
  14. 根据权利要求8~13任一所述的设备,其特征在于,若所述页面包括用于监听事件的监听模块和用于广播事件的广播模块,则所述监听模块中监听任务的优先级,比 所述广播模块中广播任务的优先级高。
PCT/CN2016/076831 2015-03-27 2016-03-21 一种加载页面模块的方法和设备 Ceased WO2016155525A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510142348.9A CN106156054B (zh) 2015-03-27 2015-03-27 一种加载页面模块的方法和设备
CN201510142348.9 2015-03-27

Publications (1)

Publication Number Publication Date
WO2016155525A1 true WO2016155525A1 (zh) 2016-10-06

Family

ID=57003872

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/076831 Ceased WO2016155525A1 (zh) 2015-03-27 2016-03-21 一种加载页面模块的方法和设备

Country Status (2)

Country Link
CN (1) CN106156054B (zh)
WO (1) WO2016155525A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106648929B (zh) * 2016-12-02 2019-06-04 武汉斗鱼网络科技有限公司 一种开关系统及开关模式实现方法
CN110020349B (zh) * 2017-09-26 2021-09-03 北京京东尚科信息技术有限公司 页面渲染的方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090013034A1 (en) * 2007-01-19 2009-01-08 International Business Machines Corporation Method, server, client and system for controlling download and display of web pages
CN102411625A (zh) * 2011-03-21 2012-04-11 苏州阔地网络科技有限公司 一种渐进式输出显示方法及装置
CN104166569A (zh) * 2014-08-15 2014-11-26 北京彩云动力教育科技有限公司 一种前端页面加载的方法及系统
CN104461543A (zh) * 2014-12-11 2015-03-25 武汉噢易云计算有限公司 一种网站页面浏览器端极速渲染的实现方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102314486A (zh) * 2011-08-04 2012-01-11 百度在线网络技术(北京)有限公司 一种用于页面浏览的方法与设备
CN103581232B (zh) * 2012-07-26 2016-12-21 中国移动通信集团公司 web页面传输方法、web页面显示装置及包含该装置的系统
US9342616B2 (en) * 2013-03-04 2016-05-17 International Business Machines Corporation User influenced asynchronous module definition loader

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090013034A1 (en) * 2007-01-19 2009-01-08 International Business Machines Corporation Method, server, client and system for controlling download and display of web pages
CN102411625A (zh) * 2011-03-21 2012-04-11 苏州阔地网络科技有限公司 一种渐进式输出显示方法及装置
CN104166569A (zh) * 2014-08-15 2014-11-26 北京彩云动力教育科技有限公司 一种前端页面加载的方法及系统
CN104461543A (zh) * 2014-12-11 2015-03-25 武汉噢易云计算有限公司 一种网站页面浏览器端极速渲染的实现方法

Also Published As

Publication number Publication date
CN106156054A (zh) 2016-11-23
CN106156054B (zh) 2019-08-30

Similar Documents

Publication Publication Date Title
US20220247833A1 (en) Installable web applications
TWI708185B (zh) 程式的運行方法及裝置、計算設備以及儲存介質
EP2948846B1 (en) Resource calling for hybrid applications
WO2020063019A1 (zh) 信息处理方法、装置、存储介质、电子设备及系统
US10666758B2 (en) Browser resource pre-pulling method, terminal and storage medium
US9274913B2 (en) Event pages for web applications and extensions
WO2020052337A1 (zh) 信息处理方法、装置、存储介质及电子设备
CN103180822A (zh) 使用共享工作器的子组件实例和同步
US10210026B2 (en) Enterprise tools enhancements
WO2016177341A1 (zh) 接口调用方法、装置及终端
US10506400B2 (en) Data download method and apparatus
CN110020370A (zh) 在客户端应用中实现动画的方法、装置及动画脚本的框架
US9059959B2 (en) Client side management of HTTP sessions
EP3788487A1 (en) Notification updates for saved sites
US10594764B2 (en) Request cache to improve web applications performance
US9892202B2 (en) Web page load time reduction by optimized authentication
CN108140037A (zh) 在后台预先实例化本原应用
US9158657B2 (en) Architecture for remote access to content state
CN104811795B (zh) 在线视频播放方法及装置
WO2016155525A1 (zh) 一种加载页面模块的方法和设备
CN109343908B (zh) 一种延迟加载js脚本的方法和装置
WO2023109113A1 (zh) 应用程序查询方法、装置、设备和存储介质
WO2017133229A1 (zh) 一种移动终端的图片显示方法和装置
CN111399928A (zh) 应用程序的启动方法、装置、电子设备及可读存储介质
US10291743B2 (en) Configuring service endpoints in native client applications

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16771280

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16771280

Country of ref document: EP

Kind code of ref document: A1