A kind of optimization method of accesses network resource, web browser and terminalTechnical field
The present invention relates to the software application field, relate in particular to a kind of optimization method, Web(webpage of accesses network resource) browser and terminal.
Background technology
Internet development is rapid, its main carrier is with HTML(Hyper Text Mark-up Language, HTML (Hypertext Markup Language)) coded file is the html web page on basis, and used a large amount of outer chained files at html web page, for example: script file (for example JavaScript file), CSS(Cascading Style Sheet, CSS (cascading style sheet)) file, image file (BMP(bitmap for example, the bitmap picture) file, JPEG(Joint Photographic Experts Group, JPEG (joint photographic experts group)) file, GIF(Graphics Interchange Format, graphic interchange format) file, PNG(Portable Network Graphic Format, streaming network graphic form) file) or the like.The page development person may exist and repeatedly use same outer chained file in the html file in writing concrete page code process, but the path of corresponding outer chained file may be different in html file.For example: the test.jpg file is at server home(homepage) under the file, at the test.jpg file under the home file, in the page, may occur following outside the path literary style of chained file, be designated as respectively: path 1, path 2:
Path 1:http: // 127.0.0.1/home/webserver/../test.jpg;
Path 2:http: // 127.0.0.1/home/httpserver/../test.jpg;
Above-mentioned path 1, path 2 all are the test.jpg file that points under the server home catalogue in fact, and it is at terminal, and the absolute path of this document is:
http://127.0.0.1/home/test.jpg。
But in the terminal browser, outside being resolved to, during the path of chained file, resolve to two different path URL(Uniform/Universal Resource Locator respectively, URL(uniform resource locator)), initiate the request of resource access to service server.Though general browser is two different URL with path 1 and path 2, be to point to same outer chained file on the service server in fact, but the terminal browser but sends twice request to service server, and all there is waste in the resource of service server resource and terminal device.When the Web file had identical and the situation that the path is different of a large amount of outer chained files, the visit simultaneously of a large amount of terminal devices can very easily cause the service server overload, and operation brings certain risk to system.
Summary of the invention
The technical problem to be solved in the present invention provides a kind of optimization method, Web browser and terminal of accesses network resource, avoiding repeatedly asking visit to service server, thereby reach the purpose of saving Internet resources and the resource of equipment own at outer chained file with different paths.
In order to solve the problems of the technologies described above, the invention provides a kind of optimization method of accesses network resource, comprising:
Receive the visit outer chained file request after, outside described, parse in the path URL(uniform resource locator) (URL) of chained file the page described outside the absolute path of chained file in service server;
Detect whether be cached with described absolute path corresponding file data,, then cancel the request of the outer chained file of described visit if having; If do not have, then initiate the request of the outer chained file of described visit.
Further, said method also has following characteristics: after the request of the outer chained file of the described visit of described initiation, also comprise:
Download described outer chained file corresponding file data, and preserve the corresponding relation of described absolute path and downloaded files data.
Further, said method also has following characteristics: described outside described, parse among the path URL of chained file the page described outside the step of the absolute path of chained file in service server comprise:
Judge whether described path URL comprises the file path symbol, if do not have, then with described path URL as the absolute path of described outer chained file in service server; If have, then simplify to handle obtaining the absolute path of described outer chained file in service server according to the implication of described file path symbol.
Further, said method also has following characteristics: described outer chained file comprises one or more in script file, CSS (cascading style sheet) file and the image file.
In order to address the above problem, the present invention also provides a kind of web page server, comprising:
Parsing module, be used to receive the request of the outer chained file of visit after, outside described, parse in the path URL(uniform resource locator) (URL) of chained file the page described outside the absolute path of chained file in service server;
The access process module is used for detecting whether be cached with described absolute path corresponding file data, if having, then cancels the request of the outer chained file of described visit; If do not have, then initiate the request of the outer chained file of described visit.
Further, above-mentioned web page server also has following characteristics: also comprise:
Download module is used for after described access process module is initiated the request of chained file outside the described visit, downloads described outer chained file corresponding file data.
Further, above-mentioned web page server also has following characteristics: also comprise:
Cache module is used to preserve the corresponding relation of described absolute path and described download module downloaded files data.
Further, above-mentioned web page server also has following characteristics:
Described parsing module, specifically be used to receive the request of the outer chained file of visit after, judge whether described path URL comprises the file path symbol, as if not having, then with described path URL as the absolute path of described outer chained file in service server; If have, then simplify to handle obtaining the absolute path of described outer chained file in service server according to the implication of described file path symbol.
Further, above-mentioned web page server also has following characteristics: described outer chained file comprises one or more in script file, CSS (cascading style sheet) file and the image file.
In order to address the above problem, the present invention also provides a kind of terminal, comprising: above-mentioned web page server.
To sum up, the invention provides a kind of optimization method, Web browser and terminal of accesses network resource, the present invention can either correctly have access to outer chained file, and can realize outreaching file path and screen processing, even the different paths of same outer chained file can be avoided repeatedly asking visit to service server, thereby reach the purpose of saving Internet resources and the resource of equipment own.
Description of drawings
Fig. 1 is the synoptic diagram of the Web server of the embodiment of the invention;
Fig. 2 is the process flow diagram of the optimization method of a kind of accesses network resource of the present invention;
Fig. 3 is the process flow diagram of optimization method of a kind of accesses network resource of the embodiment of the invention.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, hereinafter will be elaborated to embodiments of the invention in conjunction with the accompanying drawings.Need to prove that under the situation of not conflicting, embodiment among the application and the feature among the embodiment be combination in any mutually.
Fig. 1 is the synoptic diagram of the Web server of the embodiment of the invention, and as shown in Figure 1, the Web server of present embodiment comprises:
Parsing module, be used to receive the request of the outer chained file of visit after, outside described, parse among the path URL of chained file the page described outside the absolute path of chained file in service server;
The access process module is used for detecting whether be cached with described absolute path corresponding file data, if having, then cancels the request of the outer chained file of described visit; If do not have, then initiate the request of the outer chained file of described visit.
Wherein, described parsing module specifically is used for after receiving the request of the outer chained file of visit, judges whether described path URL comprises the file path symbol, as if not having, then with described path URL as the absolute path of described outer chained file in service server; If have, then simplify to handle obtaining the absolute path of described outer chained file in service server according to the implication of described file path symbol.
In the present embodiment, described Web server can also comprise:
Download module is used for after described access process module is initiated the request of chained file outside the described visit, downloads described outer chained file corresponding file data.
Cache module is used to preserve the corresponding relation of described absolute path and described download module downloaded files data.
Wherein, described outer chained file comprises one or more in script file, CSS (cascading style sheet) file and the image file.
The present invention also provides a kind of terminal, and this terminal comprises above-mentioned Web server.
Fig. 2 is the process flow diagram of the optimization method of a kind of accesses network resource of the present invention, and as shown in Figure 2, this method comprises following step:
S10, receive the visit outer chained file request after, outside described, parse among the path URL of chained file the page described outside the absolute path of chained file in service server;
Whether S20, detection are cached with described absolute path corresponding file data, if having, then cancel the request of the outer chained file of described visit; If do not have, then initiate the request of the outer chained file of described visit.
Method of the present invention can be avoided initiating repeatedly request to service server for the outer chained file that has multipath in the Web page, thereby causes the problem of the wasting of resources.
The embodiment of the invention recomputates Web browser and resolves the path URL of outer chained file in the page, for example, path symbols such as similar among the URL of path " ../", " ./", " // " are simplified calculating, the result who calculates is the absolute path that does not comprise the outer chained file of symbols such as similar " ../", " ./", " // ", detects so that Web browser carries out outer chained file related data.
Introduce the file cache function in the Web browser end side, the data of the outer chained file of soon having visited are preserved, and also preserve the mapping relations of the absolute path of outer chained file data and this outer chained file in addition.
Fig. 3 is the process flow diagram of optimization method of the accesses network resource of the embodiment of the invention, as shown in Figure 3, comprises following step:
Step 101, Web browser receive the request of the outer chained file of visit;
Step 102, Web browser are resolved the Web page, and encode the page the path URL of appointment of chained file parses absolute path outside described;
Particularly, behind the path URL that chained file defines outside Web browser is resolved, judge whether this path URL exists the file path symbol in the page, as " ../" " ./" " // " etc., as do not have above-mentioned path symbol, then do not need to carry out the path and simplify processing, directly return path URL; If the path comprises above-mentioned path symbol, then need to carry out the path and simplify processing according to the symbol implication, the path URL after the processing is the absolute path of outer chained file in service server.
Whetherstep 103, Web browser detect absolute path corresponding file data buffer memory mistake, if the buffer memory mistake then turns tostep 104; If there is not buffer memory, then turn tostep 105;
Step 104, directly use the associated documents data of buffer memory;
Step 105, download associated documents data, buffer memory this document data after download is finished, and preserve the absolute path of this document and the corresponding relation of file data, so that subsequent query.
One of ordinary skill in the art will appreciate that all or part of step in the said method can instruct related hardware to finish by program, described program can be stored in the computer-readable recording medium, as ROM (read-only memory), disk or CD etc.Alternatively, all or part of step of the foregoing description also can use one or more integrated circuit to realize.Correspondingly, each the module/unit in the foregoing description can adopt the form of hardware to realize, also can adopt the form of software function module to realize.The present invention is not restricted to the combination of the hardware and software of any particular form.
Below only be the preferred embodiments of the present invention; certainly; the present invention also can have other various embodiments; under the situation that does not deviate from spirit of the present invention and essence thereof; those of ordinary skill in the art work as can make various corresponding changes and distortion according to the present invention, but these corresponding changes and distortion all should belong to the protection domain of the appended claim of the present invention.