Disclosure of Invention
An object of the embodiments of the present invention is to provide a page display method, a page display apparatus, an electronic device, and a storage medium, so as to reduce the maintenance cost of the same module of multiple services in a front-end architecture. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a page display method, which is applied to a client, and the method includes:
obtaining a page loading request aiming at a target service;
responding to the loading request, and loading each display object in the page;
in the process of loading each display object, calling and operating a specified public function module from a specified sharing position to complete the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service.
Optionally, the invoking and executing the specified common function module from the specified shared location includes:
calling and running the designated common function module from the designated sharing position by accessing the target link; the target link is access address information which is generated after the codes corresponding to the public function module are packaged and is needed when the public function module is accessed from the specified shared position.
Optionally, the code corresponding to the common function module is written based on native JavaScript.
Optionally, the method for packaging the code corresponding to the common function module includes:
and packaging the codes corresponding to the common function modules based on a gulp technology.
Optionally, the target link includes a JS link, or the target link includes a JS link and a Cascading Style Sheet (CSS) link.
Optionally, the method for calling and running the specified common function module from the specified shared location by accessing the target link includes:
when the loading request is judged to be sent by a third application, calling and operating a specified public function module from a specified shared position by accessing a first target link corresponding to the third application;
otherwise, calling and operating the appointed public function module from the appointed shared position by accessing the second target link;
the first target link is access address information required by a third application to access the public function module, and the second target link is access address information required by the client to access the public function module.
In a second aspect, an embodiment of the present invention provides a page display apparatus, which is applied to a client, where the apparatus includes:
the acquisition module is used for acquiring a page loading request aiming at the target service;
the first loading module is used for responding to the loading request and loading each display object in the page;
the second loading module is used for calling and operating the appointed public function module from the appointed sharing position in the process of loading each display object, and completing the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service.
Optionally, the second loading module is specifically configured to call and run a specified common function module from a specified shared location by accessing the target link; the target link is access address information which is generated after the codes corresponding to the public function module are packaged and is needed when the public function module is accessed from the specified shared position.
Optionally, the code corresponding to the common function module is written based on native JavaScript.
Optionally, the apparatus further comprises:
and the packaging module is used for packaging the codes corresponding to the common function module based on a gulp technology.
Optionally, the target link includes a JS link, or the target link includes a JS link and a CSS link.
Optionally, the second loading module includes: a first loading unit and a second loading unit;
the first loading unit is used for calling and operating a specified public function module from a specified shared position by accessing a first target link corresponding to a third-party application when the loading request is judged to be sent by the third application; otherwise, triggering the second loading unit;
the second loading unit is used for calling and operating the specified public function module from the specified shared position by accessing the second target link;
the first target link is access address information required by a third application to access the public function module, and the second target link is access address information required by the client to access the public function module.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor and the communication interface complete communication between the memory and the processor through the communication bus;
a memory for storing a computer program;
a processor, configured to implement the steps of the page display method according to the first aspect when executing the program stored in the memory.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored, and the computer program, when executed by a processor, implements the steps of the page display method according to the first aspect.
In the page display method provided by the embodiment of the invention, a page loading request aiming at a target service is obtained; loading each display object in the page; in the process of loading each display object, calling and operating a specified public function module from a specified sharing position to complete the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service. Therefore, in the scheme, the same function modules of a plurality of services are called and operated from the designated sharing position as the common function modules, and the common function modules do not need to be maintained by developers of each service, but can be maintained by special developers. Therefore, the maintenance cost of the same module of a plurality of services in the front-end architecture can be reduced through the scheme.
Of course, it is not necessary for any product or method of practicing the invention to achieve all of the above-described advantages at the same time.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention.
In order to solve the problems in the prior art, embodiments of the present invention provide a page display method and apparatus, an electronic device, and a storage medium. The page display method provided by the embodiment of the invention can be applied to the client. The type of client may be various, for example: from the traffic type, the client may be a video, news, shopping, map client, etc., and from the presentation modality, the client may be an APP or web client.
As shown in fig. 1, a page display method provided by the present invention may include the following steps:
s101, a page loading request aiming at the target service is obtained.
The front-end architecture of the client can comprise a plurality of services, for example, in a video website, different services such as news, sports, art and the like can be included. There may be multiple pages per service. When a user accesses a client and needs to open a page of a certain service, the service is regarded as a target service, and then the user can send a page loading request aiming at the target service in the client through operations such as clicking, sliding and the like.
And S102, responding to the loading request, and loading each display object in the page.
After the client obtains a loading request for a page of the target service, each display object in the page can be loaded in response to the loading request. The types of display objects in the page may include: pictures, animations, videos, links, buttons, input windows and menus, etc.
S103, in the process of loading each display object, calling and operating the specified public function module from the specified sharing position to complete the loading of the display object corresponding to the public function module.
The common function module is the same function module of the target service and other services except the target service.
In each display object to be loaded, there may exist a display object corresponding to some common function module in the target service. For the display objects, the specified common function module can be called and run from the specified shared position, so that the loading of the display objects is completed. The designated public function module refers to a public function module in a target service which needs to be accessed when each display object of the page is loaded. For example, the target service includes 3 public function modules, which are respectively public function modules 1 to 3, and when each display object of the page is loaded, only the public function modules 1 and 2 in the target service need to be accessed, that is, in each display object that needs to be loaded, the display objects corresponding to the public function modules 1 and 2 respectively are included, and then, the specified public function module is the public function module 1 and 2.
In this embodiment, for a common function module, not every developer who contains a service of the common function module performs maintenance, but a dedicated developer may perform maintenance. Specifically, instead of the developer of each service maintaining the code corresponding to the common function module in the code repository of the service, a dedicated developer may maintain the code corresponding to the common function module in a separate code repository. Therefore, when the common function module needs to be accessed, the common function module can be called and operated from the designated sharing position, and the designated sharing position is the access position of the common function module.
For easy understanding, please refer to fig. 2 and fig. 3, in which fig. 2 is a schematic diagram of a front-end architecture in the prior art, and fig. 3 is a schematic diagram of a front-end architecture in an embodiment of the present invention. In the front-end architecture shown in fig. 2, for the same functional modules, namely, the header module and the menu module, of the services 1 to 3, the header module and the menu module are called in a code warehouse of each service, and are maintained by developers of each service. In the front-end architecture shown in fig. 3, the same function modules, namely, the header module and the menu module, of the services 1 to 3 are called as a common function module and are maintained by a special developer.
Applying the embodiment shown in fig. 1, obtaining a load request for a page of a target service; loading each display object in the page; in the process of loading each display object, calling and operating a specified public function module from a specified sharing position to complete the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service. It can be seen that, with the embodiment shown in fig. 1, the same function modules that are owned by a plurality of services are called and operated from the designated shared location as common function modules, and these common function modules do not need to be maintained by developers of each service, but can be maintained by dedicated developers. Therefore, the maintenance cost of the same module of a plurality of services in the front-end architecture can be reduced through the scheme.
Optionally, in an implementation manner, the invoking and executing of the specified common function module from the specified shared location in step S103 in the embodiment shown in fig. 1 may include:
calling and running the designated common function module from the designated sharing position by accessing the target link; the target link is access address information which is generated after the codes corresponding to the public function module are packaged and is needed when the public function module is accessed from the specified shared position.
When the common function module is maintained separately, in order to facilitate each service to access the common function module, the code corresponding to the common function module may be packaged, and the target link corresponding to the common function module may be generated. The target link is access address information required when accessing the common function module from the specified shared location. By accessing the target link, the specified common function module can be called and run from the specified shared location.
Specifically, the process of loading each display object of a page may be a process of running a page code corresponding to the page. Then, a target link may be introduced into the page code, so that in the process of running the page code, the target link is accessed, and the specified common function module is called and run from the specified shared location, so as to load the display object corresponding to the common function module. Illustratively, in front-end technology, the page code may be an HTML (HyperText Markup Language) file, and thus, the target link may be introduced into the HTML file corresponding to the page.
Optionally, the code corresponding to the common function module may be written based on a native JavaScript language, but is not limited thereto. A JS (JavaScript) file written based on a native JavaScript language is a JS file that is not encapsulated, i.e., does not use any frames. The code corresponding to the common function module written based on the native JavaScript language can be applied to any front-end framework type, such as exact, vue or regular.
Optionally, the method for packaging the code corresponding to the common function module may include: and packaging the codes corresponding to the common function modules based on the gulp technology. The gulp technology is an automatic construction tool in front-end development, and can be used for merging, compressing, packaging and the like of codes. In this embodiment, the code corresponding to the common function module is packaged based on the gulp technology, and the target link corresponding to the common function module may be generated.
Optionally, the target link includes a JS link, or includes a JS link and a CSS link.
When codes corresponding to the public function modules are written based on a native JavaScript language and are packaged, the packaged public function modules are JS files, the JS files contain the JS codes corresponding to the public function modules, and therefore after the codes corresponding to the public function modules are packaged, the generated target link is a JS link.
It can be appreciated that if the style of the page is not contained in the common function module, the target link only includes the JS link; if the Style of the page is included in the common function module, the target link includes a CSS (Cascading Style Sheets) link in addition to the JS link. The CSS link corresponds to a CSS file in which the specific content of the style of the defined page is contained.
Since the page loading request may be issued in the client or may be issued by a third-party application, in order to adapt to the two issuing manners, as shown in fig. 4, another page display method provided in the embodiment of the present invention may include the following steps:
s401, a page loading request aiming at the target service is obtained.
S402, responding to the loading request, and loading each display object in the page.
Steps S401 and S402 may be completely the same as steps S101 and S102 in the embodiment of fig. 1, and are not described again here.
S403, in the process of loading each display object, when judging that the loading request is sent by the third application, calling and operating the specified public function module from the specified shared position by accessing the first target link corresponding to the third application, and completing the loading of the display object corresponding to the public function module; otherwise, calling and operating the appointed public function module from the appointed sharing position by accessing the second target link, and completing the loading of the display object corresponding to the public function module.
The first target link is access address information required by the third application to access the public function module, and the second target link is access address information required by the client to access the public function module.
In practical application, the page of the target service can be opened from the client, and also can be opened from a third-party application. For example, a page of the target service is opened from an applet corresponding to the client in the third party application.
When the loading request is sent by the third-party application, namely, the page of the target service is opened from the third-party application, aiming at the specified public function module in the target service, the specified public function module can be called and operated from the specified sharing position by accessing the access address information required by accessing the public function module from the third-party application. If the page of the target service is judged not to be opened from the third-party application, namely the page of the target service is opened from the client, then aiming at the public function module appointed in the target service, the appointed public function module can be called and operated from the appointed sharing position by accessing the access address information required by accessing the public function module from the client.
That is to say, when a page is opened from the client and a page is opened from the third-party application, the specified public function module is called and operated by accessing different access addresses, and the loading of the display object corresponding to the specified public function module is completed. It can be appreciated that for the operator of the client, the operator may want the user to open the page through the third-party application when the user does not have the client software installed or it is inconvenient to open the client software. In order to facilitate that the user can open a page from the third party application, the operator may provide the third party application with specific access address information, i.e. the first target link mentioned above. Therefore, when the page of the target service is opened from the third-party application, the specified public function module can be called and operated from the specified shared position by accessing the first target link, so that the pluggable service of the client is realized, namely the public function module of the target service can be called and operated in the third-party application.
Applying the embodiment shown in fig. 4, obtaining a load request for a page of the target service; loading each display object in the page; in the process of loading each display object, when the loading request is judged to be sent by the third application, calling and operating the specified public function module from the specified shared position by accessing the first target link corresponding to the third application, and completing the loading of the display object corresponding to the public function module; otherwise, calling and operating the appointed public function module from the appointed sharing position by accessing the second target link, and completing the loading of the display object corresponding to the public function module. It can be seen that, by applying the embodiment shown in fig. 4, the same function modules that are possessed by a plurality of services are called and operated from the designated shared location as common function modules, and these common function modules do not need to be maintained by developers of each service, but can be maintained by dedicated developers. Therefore, the maintenance cost of the same module of a plurality of services in the front-end architecture can be reduced through the scheme. Moreover, when the page of the target service is opened from the third-party application, the specified public function module can be called and operated from the specified shared position by accessing the first target link, so that the pluggable service of the client is realized, namely the public function module of the target service can be called and operated in the third-party application.
An embodiment of the present invention further provides a page display apparatus, which is applied to a client, and as shown in fig. 5, the apparatus includes:
an obtaining module 501, configured to obtain a page loading request for a target service;
a first loading module 502, configured to respond to the loading request, and load each display object in the page;
a second loading module 503, configured to, in the process of loading each display object, call and run a specified common function module from a specified shared location, and complete loading of the display object corresponding to the common function module; the common function module is the same function module of the target service and other services except the target service.
Applying the embodiment shown in fig. 5, a load request for a page of the target service is obtained; loading each display object in the page; in the process of loading each display object, calling and operating a specified public function module from a specified sharing position to complete the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service. It can be seen that, with the embodiment shown in fig. 5, the same function modules that are owned by a plurality of services are called and operated from the designated shared location as common function modules, and these common function modules do not need to be maintained by developers of each service, but can be maintained by dedicated developers. Therefore, the maintenance cost of the same module of a plurality of services in the front-end architecture can be reduced through the scheme.
Optionally, the first loading module 502 is specifically configured to invoke and run a specified common function module from a specified shared location by accessing a target link; the target link is access address information which is generated after the codes corresponding to the public function module are packaged and is needed when the public function module is accessed from the specified shared position.
Optionally, the code corresponding to the common function module is written based on native JavaScript.
Optionally, the apparatus further comprises:
and the packaging module is used for packaging the codes corresponding to the common function module based on a gulp technology.
Optionally, the target link includes a JS link, or includes a JS link and a CSS link.
Since the page loading request may be issued in the client or may be issued by a third-party application, in order to adapt to the two issuing manners, as shown in fig. 6, another page display apparatus provided in the embodiment of the present invention may include:
an obtaining module 601, configured to obtain a page loading request for a target service;
a first loading module 602, configured to respond to the loading request and load each display object in the page;
a second load module 603 comprising: a first load unit 6031 and a second load unit 6032;
the first loading unit 6031 is configured to, when it is determined that the loading request is issued by a third application, call and run a specified common function module from a specified shared location by accessing a first target link corresponding to the third application; otherwise, the second load unit 6032 is triggered;
the second load unit 6032 is configured to call and run the specified common function module from the specified shared location by accessing the second target link.
The first target link is access address information required by a third application to access the public function module, and the second target link is access address information required by the client to access the public function module.
Applying the embodiment shown in fig. 6, a load request for a page of a target service is obtained; loading each display object in the page; in the process of loading each display object, when the loading request is judged to be sent by the third application, calling and operating the specified public function module from the specified shared position by accessing the first target link corresponding to the third application, and completing the loading of the display object corresponding to the public function module; otherwise, calling and operating the appointed public function module from the appointed sharing position by accessing the second target link, and completing the loading of the display object corresponding to the public function module. It can be seen that, with the embodiment shown in fig. 6, the same function modules that are owned by a plurality of services are called and operated from the designated shared location as common function modules, and these common function modules do not need to be maintained by developers of each service, but can be maintained by dedicated developers. Therefore, the maintenance cost of the same module of a plurality of services in the front-end architecture can be reduced through the scheme. Moreover, when the page of the target service is opened from the third-party application, the specified public function module can be called and operated from the specified shared position by accessing the first target link, so that the pluggable service of the client is realized, namely the public function module of the target service can be called and operated in the third-party application.
An embodiment of the present invention further provides an electronic device, as shown in fig. 7, including a processor 701, a communication interface 702, a memory 703 and a communication bus 704, where the processor 701, the communication interface 702, and the memory 703 complete mutual communication through the communication bus 704,
a memory 703 for storing a computer program;
the processor 701 is configured to implement a page display method when executing a program stored in the memory 703, where the page display method is applied to a client, and includes:
obtaining a page loading request aiming at a target service;
responding to the loading request, and loading each display object in the page;
in the process of loading each display object, calling and operating a specified public function module from a specified sharing position to complete the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service.
Optionally, the calling and executing the specified common function module from the specified shared location includes:
calling and running the designated common function module from the designated sharing position by accessing the target link; the target link is access address information which is generated after the codes corresponding to the public function module are packaged and is needed when the public function module is accessed from the specified shared position.
Optionally, the code corresponding to the common function module is written based on native JavaScript.
Optionally, the method for packaging the code corresponding to the common function module includes:
and packaging the codes corresponding to the common function modules based on the gulp technology.
Optionally, the target link includes a JS link, or the target link includes a JS link and a cascading style sheet CSS link.
Optionally, the method for calling and running the specified common function module from the specified shared location by accessing the target link includes:
when the loading request is judged to be sent by the third application, calling and operating the appointed public function module from the appointed shared position by accessing the first target link corresponding to the third application;
otherwise, calling and operating the appointed public function module from the appointed shared position by accessing the second target link;
the first target link is access address information required by the third application to access the public function module, and the second target link is access address information required by the client to access the public function module.
Applying the embodiment shown in fig. 7, a load request for a page of the target service is obtained; loading each display object in the page; in the process of loading each display object, calling and operating a specified public function module from a specified sharing position to complete the loading of the display object corresponding to the public function module; the common function module is the same function module of the target service and other services except the target service. It can be seen that, with the embodiment shown in fig. 7, the same function modules that are owned by a plurality of services are called and operated from the designated shared location as common function modules, and these common function modules do not need to be maintained by developers of each service, but can be maintained by dedicated developers. Therefore, the maintenance cost of the same module of a plurality of services in the front-end architecture can be reduced through the scheme.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the Integrated Circuit may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
In another embodiment of the present invention, a computer-readable storage medium is further provided, in which instructions are stored, and when the instructions are executed on a computer, the computer is enabled to execute the page display method in any one of the above embodiments, so as to obtain the same technical effect.
In another embodiment of the present invention, there is also provided a computer program product containing instructions, which when run on a computer, causes the computer to execute the page display method of any one of the above embodiments to obtain the same technical effect.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for embodiments such as the apparatus, the electronic device, and the storage medium, since they are substantially similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.