Summary of the invention
Fundamental purpose of the present invention is to provide a kind of JS document handling method and device, to solve the problem that in prior art, webpage loading velocity is slow.
To achieve these goals, according to an aspect of the embodiment of the present invention, a kind of JS document handling method is provided.JS document handling method according to the present invention comprises: receive webpage load request, wherein, above-mentioned webpage load request is used for request of loading target web, above-mentioned target web quotes a JS file, an above-mentioned JS file is the document framework for loading the 2nd JS file, and above-mentioned 2nd JS file is the JS file for realizing front-end functionality; Load above-mentioned target web based on above-mentioned webpage load request and on above-mentioned target web, load the above-mentioned JS file that above-mentioned target web quotes; And by the above-mentioned 2nd JS file of an above-mentioned JS files loading.
Further, an above-mentioned JS file carries the location parameter of above-mentioned 2nd JS file, above-mentioned location parameter is for representing that above-mentioned target web loads the page location of above-mentioned 2nd JS file, wherein, comprised by the above-mentioned 2nd JS file of an above-mentioned JS files loading: pass through an above-mentioned JS file by above-mentioned 2nd JS files loading to above-mentioned page location based on above-mentioned location parameter.
Further, above-mentioned 2nd JS file comprises multiple JS file, an above-mentioned JS file carries the loading sequence of above-mentioned multiple JS file, wherein, comprised by the above-mentioned 2nd JS file of an above-mentioned JS files loading: load above-mentioned multiple JS file by an above-mentioned JS file successively according to above-mentioned loading sequence.
Further, before reception webpage load request, above-mentioned JS document handling method also comprises: create an above-mentioned JS file; The parameter of the loading sequence for representing above-mentioned multiple JS file is added in an above-mentioned JS file; And an above-mentioned JS file is referred to above-mentioned target web.
Further, comprised by the above-mentioned 2nd JS file of an above-mentioned JS files loading: after having loaded an above-mentioned JS file, and before having loaded above-mentioned target web, by the above-mentioned 2nd JS file of an above-mentioned JS file Asynchronous loading; Or after having loaded above-mentioned target web, by the above-mentioned 2nd JS file of an above-mentioned JS files loading.
To achieve these goals, according to the another aspect of the embodiment of the present invention, provide a kind of JS document handling apparatus.JS document handling apparatus according to the present invention can comprise: receiving element, for receiving webpage load request, wherein, above-mentioned webpage load request is used for request of loading target web, above-mentioned target web quotes a JS file, an above-mentioned JS file is the document framework for loading the 2nd JS file, and above-mentioned 2nd JS file is the JS file for realizing front-end functionality; First loading unit, for loading above-mentioned target web based on above-mentioned webpage load request and load the above-mentioned JS file that above-mentioned target web quotes on above-mentioned target web; And second loading unit, for by the above-mentioned 2nd JS file of an above-mentioned JS files loading.
Further, an above-mentioned JS file carries the location parameter of above-mentioned 2nd JS file, above-mentioned location parameter is for representing that above-mentioned target web loads the page location of above-mentioned 2nd JS file, wherein, above-mentioned second loading unit can comprise: the first load-on module, for passing through an above-mentioned JS file by above-mentioned 2nd JS files loading to above-mentioned page location based on above-mentioned location parameter.
Further, above-mentioned 2nd JS file can comprise multiple JS file, an above-mentioned JS file carries the loading sequence of above-mentioned multiple JS file, wherein, above-mentioned second loading unit can comprise: the second load-on module, for loading above-mentioned multiple JS file by an above-mentioned JS file successively according to above-mentioned loading sequence.
Further, above-mentioned JS document handling apparatus can also comprise: creating unit, for before reception webpage load request, creates an above-mentioned JS file; Adding device, for adding the parameter of the loading sequence for representing above-mentioned multiple JS file in an above-mentioned JS file; And precedents, for an above-mentioned JS file is referred to above-mentioned target web.
Further, above-mentioned second loading unit can comprise: the 3rd load-on module, for after having loaded an above-mentioned JS file, and before having loaded above-mentioned target web, by the above-mentioned 2nd JS file of an above-mentioned JS file Asynchronous loading; Or the 4th load-on module, for after having loaded above-mentioned target web, by the above-mentioned 2nd JS file of an above-mentioned JS files loading.
According to inventive embodiments, by receiving webpage load request, wherein, webpage load request is used for request of loading target web, target web quotes a JS file, and a JS file is the document framework for loading the 2nd JS file, and the 2nd JS file is the JS file for realizing front-end functionality; Based on webpage load request loaded targets webpage and the JS file that loaded targets webpage is quoted on target web; And by JS files loading a 2nd JS file, solve the problem that in prior art, webpage loading velocity is slow, reach the effect that webpage loading velocity is accelerated.
Embodiment
It should be noted that, when not conflicting, the embodiment in the application and the feature in embodiment can combine mutually.Below with reference to the accompanying drawings and describe the present invention in detail in conjunction with the embodiments.
The present invention program is understood better in order to make those skilled in the art person, below in conjunction with the accompanying drawing in the embodiment of the present invention, technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the embodiment of a part of the present invention, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, should belong to the scope of protection of the invention.
It should be noted that, term " first ", " second " etc. in instructions of the present invention and claims and above-mentioned accompanying drawing are for distinguishing similar object, and need not be used for describing specific order or precedence.Should be appreciated that the data used like this can be exchanged, in the appropriate case so that embodiments of the invention described herein.In addition, term " comprises " and " having " and their any distortion, intention is to cover not exclusive comprising, such as, contain those steps or unit that the process of series of steps or unit, method, system, product or equipment is not necessarily limited to clearly list, but can comprise clearly do not list or for intrinsic other step of these processes, method, product or equipment or unit.
Embodiments provide a kind of JS document handling method.
Fig. 1 is the process flow diagram of the JS document handling method according to the embodiment of the present invention.As shown in Figure 1, to comprise step as follows for this JS document handling method:
Step S102, receives webpage load request, wherein, webpage load request is used for request of loading target web, target web quotes a JS file, and a JS file is the document framework for loading the 2nd JS file, and the 2nd JS file is the JS file for realizing front-end functionality.
Step S104, based on webpage load request loaded targets webpage and the JS file that loaded targets webpage is quoted on target web.
Step S106, by JS files loading a 2nd JS file.
The front-end functionality of website can be quoted third-party JS file and complete.Wherein, when providing the JS file of certain front-end functionality, at least two JS files can be provided, as a JS file and the 2nd JS file.One JS file may be used for the function realizing loading other JS files, one JS file is equivalent to a functional document framework, and because this JS file is document framework, its file content can be enough little, like this, a JS file of loading does not affect page loading substantially.
Particularly, when target web quotes JS file, only quote a JS file, and in a JS file, load the 2nd JS file again after a JS files loading completes, by loading the front-end functionality that the 2nd JS file realize target page is wanted to load.Wherein, the 2nd JS file can be a JS file, also can be multiple JS file.Such as the 2nd JS file comprises: JS file A, JS file B and JS file C.When the 2nd JS file comprises multiple JS file, if when providing third party JS file, the loading frame i.e. JS file that one very little can be first provided, after a JS files loading completes, a JS file A is loaded with specific load mode at concrete target pages again in a JS file, after JS file A has loaded, reload JS file B, finally, after JS file B has loaded, reload JS file C.Wherein, specific load mode can be the location parameter that carries according to himself of a JS file and sequence parameter, and this sequence parameter is the sequence parameter of loading the 2nd JS file, realizes the loading to the 2nd JS file.
According to the embodiment of the present invention, due to target web quote JS file time, only refer to a JS file, during loaded targets webpage, a JS file is loaded, because a JS file is that document framework loading velocity is fast, after a JS files loading completes, can other elements rapidly on loaded targets webpage and the 2nd JS file, like this, the loading velocity of the mode influences webpage avoiding the obstruction due to JS file to load, thus reach the effect improving webpage loading velocity.
Preferably, in embodiments of the present invention, one JS file carries the location parameter of the 2nd JS file, location parameter is for representing that target web loads the page location of the 2nd JS file, wherein, can be comprised by JS files loading a 2nd JS file: position-based parameter passes through a JS file by the 2nd JS files loading to page location.
Such as, when target web quotes a JS file, a JS file can be quoted at any page location of this webpage.Because a JS file carries the location parameter of the 2nd JS file, therefore, a JS file can be specified the 2nd JS file to load before </body> or be loaded at the page location of specifying.Like this, avoid each JS file and limit oneself refers in the page, cause and quote troublesome problem.
Preferably, in embodiments of the present invention, the 2nd JS file can comprise multiple JS file, and a JS file carries the loading sequence of multiple JS file, wherein, can be comprised by JS files loading a 2nd JS file: load multiple JS file by a JS file successively according to loading sequence.
Because a JS file carries the loading sequence of the 2nd JS file, therefore the loading sequence of the 2nd JS file is by a JS document control.Such as, the 2nd JS file comprises multiple JS file: JS file A, JS file B and JS file C.After a JS files loading completes, JS file A reloads JS file B after having been loaded by the loading sequence in a JS file, finally, reloads JS file C after JS file B has loaded.If there is JS file (as JS file B) larger or more consuming time in the 2nd JS file, the loading sequence of JS file B can be discharged to finally by a JS file.Particularly, order also can be adjusted to by the one JS file: in a JS file, first unblock loads JS file A, after JS file A has loaded, reloads JS file C, last after JS file C has loaded, reload JS file B larger or more consuming time.Like this, avoid to only have and be completely loaded with current JS file, just can continue the problem of other elements in load page.Further, also avoid due to JS file access time-out in loading procedure, the page can be waited for until go to load the problem of other elements after time-out more always.Owing to avoiding the problems referred to above, therefore reach the effect improving webpage loading velocity.
Preferably, in embodiments of the present invention, before reception webpage load request, JS document handling method can also comprise:
S2, creates a JS file.
S4, adds the parameter of the loading sequence for representing multiple JS file in a JS file.
S6, refers to target web by a JS file.
Before target web quotes a JS file, can be pre-created a JS file, and add the parameter of the loading sequence representing multiple JS file in a JS file, the plurality of JS file is the JS file in the 2nd JS file.2nd JS file multiple JS files that it comprises by the sequence parameter loading in a JS file.
Preferably, in embodiments of the present invention, can be comprised by JS files loading a 2nd JS file: after having loaded a JS file, and before having loaded target web, by JS file Asynchronous loading a 2nd JS file; Or, after having loaded target web, by JS files loading a 2nd JS file.
In the embodiment of the present invention, after having loaded a JS file, reload the web page element after this JS file, 2nd JS file can be loaded after a JS files loading is complete and before web page element has loaded, and also can be a JS files loading is complete after and web page element has loaded afterwards loading.
The embodiment of the present invention additionally provides a kind of JS document handling apparatus.This device can realize its function by computer equipment.It should be noted that, the JS document handling apparatus of the embodiment of the present invention may be used for performing the JS document handling method that the embodiment of the present invention provides, and the JS document handling apparatus that the JS document handling method of the embodiment of the present invention also can be provided by the embodiment of the present invention performs.
Fig. 2 is the schematic diagram of the JS document handling apparatus according to the embodiment of the present invention.As shown in Figure 2, this JS document handling apparatus can comprise: receiving element 10, first loading unit 20 and the second loading unit 30.
Receiving element 10 is for receiving webpage load request, wherein, webpage load request is used for request of loading target web, and target web quotes a JS file, one JS file is the document framework for loading the 2nd JS file, and the 2nd JS file is the JS file for realizing front-end functionality.
First loading unit 20 is for based on webpage load request loaded targets webpage and the JS file that loaded targets webpage is quoted on target web.
Second loading unit 30 is for passing through JS files loading a 2nd JS file.
The front-end functionality of website can be quoted third-party JS file and complete.Wherein, when providing the JS file of certain front-end functionality, at least two JS files can be provided, as a JS file and the 2nd JS file.One JS file may be used for the function realizing loading other JS files, one JS file is equivalent to a functional document framework, and because this JS file is document framework, its file content can be enough little, like this, a JS file of loading does not affect page loading substantially.
Particularly, when target web quotes JS file, only quote a JS file, and in a JS file, load the 2nd JS file again after a JS files loading completes, by loading the front-end functionality that the 2nd JS file realize target page is wanted to load.Wherein, the 2nd JS file can be a JS file, also can be multiple JS file.Such as the 2nd JS file comprises: JS file A, JS file B and JS file C.When the 2nd JS file comprises multiple JS file, if when providing third party JS file, the loading frame i.e. JS file that one very little can be first provided, after a JS files loading completes, a JS file A is loaded with specific load mode at concrete target pages again in a JS file, after JS file A has loaded, reload JS file B, finally, after JS file B has loaded, reload JS file C.Wherein, specific load mode can be the location parameter that carries according to himself of a JS file and sequence parameter, and this sequence parameter is the sequence parameter of loading the 2nd JS file, realizes the loading to the 2nd JS file.
According to the embodiment of the present invention, due to target web quote JS file time, only refer to a JS file, during loaded targets webpage, a JS file is loaded, because a JS file is that document framework loading velocity is fast, after a JS files loading completes, can other elements rapidly on loaded targets webpage and the 2nd JS file, like this, the loading velocity of the mode influences webpage avoiding the obstruction due to JS file to load, thus reach the effect improving webpage loading velocity.
Preferably, in embodiments of the present invention, one JS file carries the location parameter of the 2nd JS file, location parameter is for representing that target web loads the page location of the 2nd JS file, wherein, second loading unit 30 can comprise: the first load-on module, passes through a JS file by the 2nd JS files loading to page location for position-based parameter.
Such as, when target web quotes a JS file, a JS file can be quoted at any page location of this webpage.Because a JS file carries the location parameter of the 2nd JS file, therefore, a JS file can be specified the 2nd JS file to load before </body> or be loaded at the page location of specifying.Like this, avoid each JS file and limit oneself refers in the page, cause and quote troublesome problem.
Preferably, in embodiments of the present invention, 2nd JS file can comprise multiple JS file, one JS file carries the loading sequence of multiple JS file, wherein, second loading unit 30 can comprise: the second load-on module, for loading multiple JS file by a JS file successively according to loading sequence.
Because a JS file carries the loading sequence of the 2nd JS file, therefore the loading sequence of the 2nd JS file is by a JS document control.Such as, the 2nd JS file comprises multiple JS file: JS file A, JS file B and JS file C.After a JS files loading completes, JS file A reloads JS file B after having been loaded by the loading sequence in a JS file, finally, reloads JS file C after JS file B has loaded.If there is JS file (as JS file B) larger or more consuming time in the 2nd JS file, the loading sequence of JS file B can be discharged to finally by a JS file.Particularly, order also can be adjusted to by the one JS file: in a JS file, first unblock loads JS file A, after JS file A has loaded, reloads JS file C, last after JS file C has loaded, reload JS file B larger or more consuming time.Like this, avoid to only have and be completely loaded with current JS file, just can continue the problem of other elements in load page.Further, also avoid due to JS file access time-out in loading procedure, the page can be waited for until go to load the problem of other elements after time-out more always.Owing to avoiding the problems referred to above, therefore reach the effect improving webpage loading velocity.
Preferably, in embodiments of the present invention, JS document handling apparatus can also comprise: creating unit, for before reception webpage load request, creates a JS file; Adding device, for adding the parameter of the loading sequence for representing multiple JS file in a JS file; And precedents, for a JS file is referred to target web.
Before target web quotes a JS file, can be pre-created a JS file, and add the parameter of the loading sequence representing multiple JS file in a JS file, the plurality of JS file is the JS file in the 2nd JS file.2nd JS file multiple JS files that it comprises by the sequence parameter loading in a JS file.
Preferably, in embodiments of the present invention, the second loading unit 30 can comprise: the 3rd load-on module, for after having loaded a JS file, and before having loaded target web, by JS file Asynchronous loading a 2nd JS file; Or the 4th load-on module, for after having loaded target web, by JS files loading a 2nd JS file.
In the embodiment of the present invention, after having loaded a JS file, reload the web page element after this JS file, 2nd JS file can be loaded after a JS files loading is complete and before web page element has loaded, and also can be a JS files loading is complete after and web page element has loaded afterwards loading.
It should be noted that, for aforesaid each embodiment of the method, in order to simple description, therefore it is all expressed as a series of combination of actions, but those skilled in the art should know, the present invention is not by the restriction of described sequence of movement, because according to the present invention, some step can adopt other orders or carry out simultaneously.Secondly, those skilled in the art also should know, the embodiment described in instructions all belongs to preferred embodiment, and involved action and module might not be that the present invention is necessary.
In the above-described embodiments, the description of each embodiment is all emphasized particularly on different fields, in certain embodiment, there is no the part described in detail, can see the associated description of other embodiments.
In several embodiments that the application provides, should be understood that, disclosed device, the mode by other realizes.Such as, device embodiment described above is only schematic, the such as division of described unit, be only a kind of logic function to divide, actual can have other dividing mode when realizing, such as multiple unit or assembly can in conjunction with or another system can be integrated into, or some features can be ignored, or do not perform.Another point, shown or discussed coupling each other or direct-coupling or communication connection can be by some interfaces, and the indirect coupling of device or unit or communication connection can be electrical or other form.
The described unit illustrated as separating component or can may not be and physically separates, and the parts as unit display can be or may not be physical location, namely can be positioned at a place, or also can be distributed in multiple network element.Some or all of unit wherein can be selected according to the actual needs to realize the object of the present embodiment scheme.
In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, also can be that the independent physics of unit exists, also can two or more unit in a unit integrated.Above-mentioned integrated unit both can adopt the form of hardware to realize, and the form of SFU software functional unit also can be adopted to realize.
If described integrated unit using the form of SFU software functional unit realize and as independently production marketing or use time, can be stored in a computer read/write memory medium.Based on such understanding, the part that technical scheme of the present invention contributes to prior art in essence in other words or all or part of of this technical scheme can embody with the form of software product, this computer software product is stored in a storage medium, comprises all or part of step of some instructions in order to make a computer equipment (can be personal computer, mobile terminal, server or the network equipment etc.) perform method described in each embodiment of the present invention.And aforesaid storage medium comprises: USB flash disk, ROM (read-only memory) (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), portable hard drive, magnetic disc or CD etc. various can be program code stored medium.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any amendment done, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.