Summary of the invention
For solving the problems of the technologies described above, the embodiment of the invention provides a kind of Web front end resource request disposal route and device, and technical scheme is as follows:
The embodiment of the invention provides a kind of Web front end resource request disposal route, and the method comprises:
Receive the page resource request message that user side sends;
Described page resource request message is resolved, determine the concrete object resource that this message is asked;
According to determined concrete object resource, obtain the corresponding resource file of pre-save;
The object resource file that obtains is merged, obtain resource file and merge bag;
Described resource file is merged bag return described user side.
According to a kind of embodiment of the present invention, after the page resource request message that receives the user side transmission, also comprise:
Whether the request object of judging this message is Web front end resource, if so, then further carries out subsequent step.
According to a kind of embodiment of the present invention, described according to determined concrete object resource, the corresponding resource file of acquisition pre-save comprises:
Utilize the sign of object resource, obtain the corresponding resource file of pre-save by search.
According to a kind of embodiment of the present invention, described the object resource file that obtains is merged, comprising:
According to the type of object resource file, dissimilar object resource files is merged respectively.According to a kind of embodiment of the present invention,
After obtaining resource file merging bag, also comprise: resource file is merged bag compress;
Described described resource file merging is wrapped returned described user side, and be specially: the resource file after will compressing merges bag and returns described user side.
The embodiment of the invention also provides a kind of Web front end resource request treating apparatus, and this device comprises:
The request receiving module is used for receiving the page resource request message that user side sends;
The request analysis module is used for described page resource request message is resolved, and determines the concrete object resource that this message is asked;
The resource transfer module is used for according to determined concrete object resource, obtains the corresponding resource file of pre-save;
Resource merges module, is used for the object resource file that obtains is merged, and obtains resource file and merges bag;
The request respond module is used for that described resource file is merged bag and returns described user side.
According to a kind of embodiment of the present invention, the described request parsing module also is used for:
After the page resource request message that receives the user side transmission, judge whether the request object of this message is Web front end resource, if so, then further this message is resolved.
According to a kind of embodiment of the present invention, described resource transfer module specifically is used for:
Utilize the sign of object resource, obtain the corresponding resource file of pre-save by search.
According to a kind of embodiment of the present invention, described resource merges module, specifically is used for:
According to the type of object resource file, dissimilar object resource files is merged respectively.
According to a kind of embodiment of the present invention, described resource merges module, is used for that also resource file is merged bag and compresses;
The described request respond module, the concrete bag for the merging of the resource file after will compressing returned described user side.
The technical scheme that the embodiment of the invention provides compared with prior art, resource file is not to merge in advance to be stored in statically in the Website server, but by the resource request of server end according to client, dynamically resource file is merged, allow the developer not be used in a large amount of time and efforts of cost in the merging of resource file, effectively reduce the development amount, also need to not locate deploy resources the developer and merge instrument, reduced cost of development.On the other hand, situation for the multiple person cooperational exploitation, the employed common source of different developers can not duplicate the situation of merging, has both promoted the development efficiency of team's integral body, can carry out more efficiently maintenance and management to the resource of server end storage again.
Embodiment
In the prior art, the Website development person adopts the method that a plurality of resource files are merged and compress, thereby realizes reducing the http request, promotes the purpose of user's access speed.According to the general exploitation custom of website, the exploitation of the exploitation of various front end resources and website overall page is relatively independent process.In order to improve accelerating website access, after the resource file that development of resources person writes oneself merges and compresses, save as static file and be uploaded to Website server, the page development person on stream, the resource file merging bag label that needs are called writes in the html file, when user's access websites page, user browser directly obtains the developer from Website server according to the content of html file and merges in advance good resource bundle.
Above-mentioned development scheme, more effective in the exploitation of personal development or small-scale website, if but the website is larger, when needing the multiple person cooperational exploitation, need to dispose a whole set of at each development of resources person place and merge tool of compression, promoted cost of development, and each development of resources person needs manually to merge squeeze operation, reduced development efficiency; In addition, for some resources comparatively commonly used, may can carry out merging and the compression of repetition between a plurality of development of resources persons, the development efficiency that this not only can affect whole team has also increased the maintenance difficulties of server end resource file.
For the problems referred to above, the embodiment of the invention provides a kind of Web front end resource request disposal route, and the method may further comprise the steps:
Receive the page resource request message that user side sends;
Described page resource request message is resolved, determine the concrete object resource that this message is asked;
According to determined concrete object resource, obtain the corresponding resource file of pre-save;
The object resource file that obtains is merged, obtain resource file and merge bag;
Described resource file is merged bag return described user side.
The executive agent of said method can be Website server itself, also can be positioned within the Website server or outside the module of a function opposite independent.Compared with prior art, resource file is not to merge in advance to be stored in statically in the Website server, but by the resource request of server end according to client, dynamically resource file is merged.
Use technical solution of the present invention, the developer need to not reduce the development amount effectively in a large amount of time and efforts of merging cost of resource file, need to not locate deploy resources the developer yet and merge instrument, has reduced cost of development.On the other hand, situation for the multiple person cooperational exploitation, the employed common source of different developers can not duplicate the situation of merging, has both promoted the development efficiency of team's integral body, can carry out more efficiently maintenance and management to the resource of server end storage again.
Need to prove, use technical solution of the present invention, although when each user asks Web front end resource, all need to carry out union operation, but in actual applications, the calculated performance of server is far above common subscriber computer or developing engine, therefore it is very high to merge the efficient of processing, and can't cause on the speed of user's access websites obvious impact.And, owing to be to carry out Dynamic merge for the concrete resource that the user asks, itself can also avoid existing in a plurality of merged files in the prior art situation that repeats resource content to occur, therefore only from this point of view, the present invention program also can improve the response efficiency to user's access effectively.
In order to make those skilled in the art understand better technical scheme among the present invention, below in conjunction with the accompanying drawing in the embodiment of the invention, technical scheme in the embodiment of the invention is described in detail, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, the every other embodiment that those of ordinary skills obtain should belong to the scope of protection of the invention.
Shown in Figure 1, be the process flow diagram of a kind of Web front end resource request disposal route provided by the present invention, the method can may further comprise the steps:
S101 receives the page resource request message that user side sends;
When the user needs browsing website contents, network address corresponding to input in the browser of user side, browser is according to the network address of user's input, and to the Website server transmission page resource request message of correspondence, this message is generally sent in the mode of http request.
Website server is made response for the content that this message is asked after receiving the page resource request message of user side transmission, returns corresponding resource to user side, and detailed process sees below continuous step.
S102 resolves the page resource request message, determines the concrete object resource that this message is asked;
The page resource request message that server end is sent user side is resolved, and determines current concrete which content of request that needs of user side.
In actual applications, needing the resource called in the displayed web page process, is to be write in the html file of webpage by the resource tag that the webpage development personnel call needs when the exploitation in advance.In the prior art, the development of resources personnel merge a plurality of resource files in advance, the resource file label that the page development personnel need to call after will merging writes in the html file, and that is to say: when user's access websites, Website server directly will merge good file and return to the user.
And in the present invention, the development of resources personnel can't merge a plurality of resources in advance, different resource files is that the form of disperseing is preserved at server end, correspondingly, the page development personnel also are the resources that needs are called, and write respectively the html file with the resource file label of discrete form.Therefore, server end needs by the parsing to this message after receiving the page resource request message, determines current concrete which the concrete resource file of request that needs of user side.
In a kind of embodiment of the present invention, server end also can at first be judged by logic after receiving the page resource request message, determine the resource type of user side current request.If the front end resource is asked, then further carry out subsequent step; If the other types resource is asked, then return corresponding resource file according to existing normal flow to the user.Certainly, be understandable that fundamental purpose of the present invention is exactly the request problem that solves the front end resource, so this step is not to carry out for the present invention.
S103 according to determined concrete object resource, obtains the corresponding resource file of pre-save;
The concrete object resource that server end calls according to determined current needs obtains corresponding resource file from the resource pool of Website server.Because in the present invention, resource file is that the form of disperseing is kept in the server, therefore in this step, also needs according to analysis result, obtains respectively each resource file.
In actual applications, to the analysis result of resource request message may direct corresponding resource file store path, in this case, can directly obtain corresponding resource file according to analysis result; If the analysis result to resource request message is certain sign (for example resource name, resource ID etc.) of resource file, then can be identified in the resource pool of server according to this and searches for, thereby obtain and marking matched resource file.Concrete searching method and search strategy can arrange flexibly according to practical application scene and application demand, do not need in embodiments of the present invention to be elaborated.
S104 merges the object resource file that obtains, and obtains resource file and merges bag;
In this step, server end carries out union operation for a plurality of object resource files that obtain, and obtains (or quantity relatively less several) file bag.In a kind of preferred implementation of the present invention, can according to the type of object resource file, dissimilar object resource files be merged respectively.For example CSS file and JavaScript file are merged respectively, obtain CSS resource bundle and resource bundle.
In addition, because merging bag, resource file finally need to return to user side, need to be in the data volume of transmission over networks in order to reduce, and the file after can also further being combined compresses, to improve transfer efficiency.
Be understandable that according to goal of the invention of the present invention, the step that resource file merging bag is compressed not is necessary.In addition in actual applications, merge and compress two kinds of operations and do not have absolute sequencing, for example, can compress the resource file that disperses first, then merge.A kind of mode more commonly used then is to merge to mix with squeeze operation to carry out.For example, the instruments such as YUICompressor, UglifyJs commonly used, Google Closure can effectively merge and compression CSS file and JavaScript file at present.Certainly, the present invention does not need to be combined or compresses the concrete scheme that adopts and limits.
S105 merges bag with resource file and returns user side.
The resource file that obtains for merging merges bag, and server turns back to user side with it, the browser of user side in this mergings bag content resolve, utilize the content realization page rendering that parses.Done the compression processing if further resource file is merged bag in S104, the resource file after then will compressing in this step merges bag and returns to user side.
As seen, among the present invention program compared with prior art, difference be merging bag of the prior art be pre-save in server, and merging of the present invention Bao Ze to be request dynamic according to user side generate.And for user side, not difference of the merging bag flesh and blood that finally receives, so the present invention program's enforcement does not need to change the user is distolateral.
Corresponding to top embodiment of the method, the present invention also provides a kind of Web front end resource request treating apparatus, it is characterized in that, this device comprises: request receiving module 210, request analysis module 220, resource transfer module 230, resource merge module 240 and request respond module 250, and the below does the cooperation relation of the concrete function of modules and intermodule respectively and specifies.
Request receiving module 210 is used for receiving the page resource request message that user side sends;
When the user needs browsing website contents, network address corresponding to input in the browser of user side, browser is according to the network address of user's input, and to the Website server transmission page resource request message of correspondence, this message is generally sent in the mode of http request.
After request receiving module 210 receives the page resource request message of user side transmission, this message is forwarded to request analysis module 220 does further processing.
Request analysis module 220 is used for the page resource request message is resolved, and determines the concrete object resource that this message is asked;
The page resource request message that 220 pairs of user sides of request analysis module are sent is resolved, and determines current concrete which content of request that needs of user side.
In actual applications, needing the resource called in the displayed web page process, is to be write in the html file of webpage by the resource tag that the webpage development personnel call needs when the exploitation in advance.In the prior art, the development of resources personnel merge a plurality of resource files in advance, the resource file label that the page development personnel need to call after will merging writes in the html file, and that is to say: when user's access websites, Website server directly will merge good file and return to the user.
And in the present invention, the development of resources personnel can't merge a plurality of resources in advance, different resource files is that the form of disperseing is preserved at server end, correspondingly, the page development personnel also are the resources that needs are called, and write respectively the html file with the resource file label of discrete form.Therefore, request analysis module 220 needs by the parsing to this message after receiving the page resource request message, determines current concrete which the concrete resource file of request that needs of user side.
In a kind of embodiment of the present invention, request analysis module 220 also can at first be judged by logic after receiving the page resource request message, determine the resource type of user side current request.If the front end resource is asked, then further carry out subsequent operation; If the other types resource is asked, then return corresponding resource file according to existing normal flow to the user.Certainly, be understandable that fundamental purpose of the present invention is exactly the request problem that solves the front end resource, so this decision operation is not to carry out for the present invention.
Resource transfer module 230 is used for according to determined concrete object resource, obtains the corresponding resource file of pre-save;
The concrete object resource that resource transfer module 230 is called according to determined current needs obtains corresponding resource file from the resource pool of Website server.Because in the present invention, resource file is that the form of disperseing is kept in the server, so resource transfer module 230 also needs according to analysis result, obtains respectively each resource file.
In actual applications, to the analysis result of resource request message may direct corresponding resource file store path, in this case, resource transfer module 230 can directly be obtained corresponding resource file according to analysis result; If the analysis result to resource request message is certain sign (for example resource name, resource ID etc.) of resource file, then resource transfer module 230 can be identified in the resource pool of server according to this and search for, thereby obtains and marking matched resource file.Concrete searching method and search strategy can arrange flexibly according to practical application scene and application demand, do not need in embodiments of the present invention to be elaborated.
Resource merges module 240, is used for the object resource file that obtains is merged, and obtains resource file and merges bag;
Resource merges module 240 for a plurality of object resource files that obtain, and carries out union operation, obtains (or quantity relatively less several) file bag.In a kind of preferred implementation of the present invention, can according to the type of object resource file, dissimilar object resource files be merged respectively.For example CSS file and JavaScript file are merged respectively, obtain CSS resource bundle and resource bundle.
In addition, because merging bag, resource file finally need to return to user side, need to be in the data volume of transmission over networks in order to reduce, and the file that resource merges after module 240 can also further be combined compresses, to improve transfer efficiency.
Be understandable that according to goal of the invention of the present invention, the step that resource file merging bag is compressed not is necessary.In addition in actual applications, merge and compress two kinds of operations and do not have absolute sequencing, for example, can compress the resource file that disperses first, then merge.A kind of mode more commonly used then is to merge to mix with squeeze operation to carry out.For example, the instruments such as YUICompressor, UglifyJs commonly used, Google Closure can effectively merge and compression CSS file and JavaScript file at present.Certainly, the present invention does not need to be combined or compresses the concrete scheme that adopts and limits.
Request respond module 250 is used for that resource file is merged bag and returns user side.
The resource file that obtains for merging merges bag, and request respond module 250 turns back to user side with it, the browser of user side in this mergings bag content resolve, utilize the content realization page rendering that parses.Done the compression processing if further resource file is merged bag in resource merging module 240, the resource file merging bag after then asking will compress in the respond module 250 returns to user side.
For the convenience of describing, be divided into various unit with function when describing above device and describe respectively.Certainly, when enforcement is of the present invention, can in same or a plurality of softwares and/or hardware, realize the function of each unit.
As seen through the above description of the embodiments, those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential general hardware platform.Based on such understanding, the part that technical scheme of the present invention contributes to prior art in essence in other words can embody with the form of software product, this computer software product can be stored in the storage medium, such as ROM/RAM, magnetic disc, CD etc., comprise that some instructions are with so that a computer equipment (can be personal computer, server, the perhaps network equipment etc.) carry out the described method of some part of each embodiment of the present invention or embodiment.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and identical similar part is mutually referring to getting final product between each embodiment, and each embodiment stresses is difference with other embodiment.Especially, for device embodiment, because its basic simlarity is in embodiment of the method, so describe fairly simplely, relevant part gets final product referring to the part explanation of embodiment of the method.Device embodiment described above only is schematic, wherein said module as the separating component explanation can or can not be physically to separate also, the parts that show as module can be or can not be physical locations also, namely can be positioned at a place, perhaps also can be distributed on a plurality of network element.Can select according to the actual needs wherein some or all of module to realize the purpose of present embodiment scheme.Those of ordinary skills namely can understand and implement in the situation of not paying creative work.
The above only is the specific embodiment of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.