The disclosure relates to a terminal browser technology of Internet, and in particular to a script processing method and a script processing system for a browser.
At present, the execution of JavaScript codes in a webpage needs to include the following steps on a standard Personal Computer (PC) browser.
1. The browser on the PC compiles the JavaScript source code and converts the JavaScript source code into a binary bytecode that can be used by a JavaScript virtual machine.
2. The JavaScript virtual machine on the browser executes the corresponding binary bytecode.
The JavaScript is a common scripting language in present browsers.
The execution of JavaScript codes on the PC browser has a high requirement on the processing capability of Central Processing Unit (CPU) and the size of memory space. However, the present mobile terminal (for example, mobile phone) is seriously limited in both the processing capability of CPU and the size of memory space. Therefore, most mobile terminals cannot meet the requirement of JavaScript code execution on the PC browser, which makes it difficult to apply the JavaScript code execution on the PC browser to mobile terminals. The prior art fails to provide a solution to the above technical problems, which causes inconveniences in actual application.
In view of the above, the main purpose of the disclosure is to provide a script processing method and a script processing system for a browser, to enable the browser of a mobile terminal to support the execution of JavaScript.
To achieve the purpose above, the disclosure provides the following technical solutions.
The disclosure provides a script processing method for a browser, which includes:
receiving, by a proxy server, a Uniform Resource Locator (URL) transmitted from a client; and requesting, by the proxy server, a page from an Internet server corresponding to the URL, compiling a script code of the page returned from the Internet server into a binary bytecode, and transmitting the binary bytecode to the client.
The method may further include:
receiving, by the proxy server, a Hypertext Markup Language (HTML) file of the page returned from the Internet server after requesting the page from the Internet server, converting the HTML file of the page into a binary Document Object Model (DOM) tree structure, and transmitting the DOM tree structure to the client.
After the proxy server transmits the DOM tree structure to the client, the method may further include:
rendering, by the client, content of the DOM tree structure on the page.
The script code may be JavaScript code or VBScript code.
The disclosure further provides a script processing method for a browser, which includes:
transmitting, by a client. a Uniform Resource Locator (URL) requested by a user to a proxy server; and
receiving, by the client, a binary bytecode transmitted by the proxy server, and executing the binary bytecode; wherein the binary bytecode is obtained by the proxy server by requesting a page from an Internet server corresponding to the URL and compiling the script code of the page returned from the Internet server.
After the client transmits the URL to the proxy server, the client receives a DOM tree structure transmitted by the proxy server and renders the content of the DOM tree structure on the page, wherein the DOM tree structure is obtained by the proxy server by converting a HTML file of the page returned from the Internet server.
The disclosure further provides a script processing system for a browser, which includes a client, a proxy server and an Internet server.
The client is configured to transmit a Uniform Resource Locator (URL) requested by a user to the proxy server and to execute a binary bytecode returned from the proxy server.
The proxy server is configured to request a page from the Internet server corresponding to the URL, to compile the script code of the page returned from the Internet server into a binary bytecode, and to transmit the binary bytecode to the client; and
the Internet server is configured to provide the script code of the page to the proxy server according to a request from the proxy server.
The Internet server is further configured to transmit a Hypertext Markup Language (HTML) file of the page to the proxy server after receiving the page request from the proxy server.
The proxy server is further configured to convert the HTML file of the page into a binary DOM tree structure and to transmit the DOM tree structure to the client.
The client is further configured to render the content of the DOM tree structure on the page after receiving the DOM tree structure from the proxy server.
The script code may be a JavaScript code or VBScript code.
The disclosure further provides a proxy server, which includes: a Uniform Resource Locator (URL) receiving module, a page request module, and a compiling and transmitting module.
The URL receiving module is configured to receive a URL from a client and to notify the page request module.
The page request module is configured to request a page from an Internet server corresponding to the URL.
The compiling and transmitting module is configured to compile the script code of the page returned from the Internet server into a binary bytecode and to transmit the binary bytecode to the client.
The compiling and transmitting module is further configured to: receive a HTML file of the page returned from the Internet server after the page request module requests a page from the Internet server, convert the HTML file of the page into a binary DOM tree structure, and transmit the binary DOM tree structure to the client.
The script code may be a JavaScript code or VBScript code.
The disclosure further provides a client, which includes: a Uniform Resource Locator (URL) transmitting module, and a receiving and executing module.
The URL transmitting module is configured to transmit a URL requested by a user to a proxy server.
The receiving and executing module is configured to: receive a binary bytecode transmitted by the proxy server and execute the binary bytecode. The binary bytecode is obtained by the proxy server by requesting a page from an Internet server corresponding to the URL and compiling the script code of the page returned from the Internet server.
The receiving and executing module is further configured to: receive a DOM tree structure transmitted by the proxy server after the URL transmitting module transmits the URL, and render content of the DOM tree structure on the page. The DOM tree structure is obtained by the proxy server by converting a HTML file of the page returned from the Internet server.
With the script processing method and the script processing system for a browser provided by the disclosure, the compilation and the execution of the browser script code are conducted separately, which is that the browser script code is compiled into a binary bytecode on the proxy server before being transmitted to the browser client of the mobile terminal, and the browser client of the mobile terminal execute the binary bytecode compiled by the proxy server directly. The disclosure effectively reduces the overhead of script code compilation on the mobile terminal browser, thereby enabling the mobile terminal browser to support the execution of script code.
The technical solution of the disclosure is illustrated below in more detail in conjunction with accompanying drawings and specific embodiments.
To enable the browser of a mobile terminal to support the execution of script codes (e.g., JavaScript), the disclosure provides a script processing method for a browser. As shown in
Step 101: A proxy server receives a Uniform Resource Locator (URL) transmitted from a client.
The client transmits the URL requested by a user to the proxy server.
When accessing a website, a user may click or input an address (i.e., URL) of the needed website on a browser client of a mobile terminal used by the user. Then, the browser client of the mobile terminal records the URL clicked or input by the user and transmits the recorded URL to the proxy server.
Step 102: The proxy server requests a page from an Internet server corresponding to the URL, compiles a script code of the page returned from the Internet server into a binary bytecode, and transmits the binary bytecode to the client.
After the proxy server receives the URL transmitted by the client, the proxy server finds an Internet server corresponding to the URL and transmits a page request to the Internet server. After the Internet server receives the page request from the proxy server, the Internet server returns the script code of the corresponding page to the proxy server. The proxy server compiles the script code of the page returned from the Internet server into a binary bytecode that can be used by a JavaScript virtual machine of the browser client, and transmits the binary bytecode to the client.
Step 103: The client executes the received binary bytecode.
After the client receives the binary bytecode returned from the proxy server, the client executes the corresponding binary bytecode through the JavaScript virtual machine.
It should be noted that the Internet server needs to transmit a Hypertext Markup Language (HTML) file of the page to the proxy server after receiving the page request from the proxy server, then the proxy server converts the HTML file of the page into a binary DOM tree structure and transmits the DOM tree structure to the client, and finally the client renders the content of the DOM tree structure on the page.
Corresponding to the script processing method for a browser, the disclosure also provides a script processing system for the browser. As shown in
Preferably, the Internet server 30 is further configured to transmit a HTML file of the page to the proxy server 20 after receiving the page request from the proxy server 20.
Correspondingly, the proxy server 20 is further configured to convert the HTML file of the page into a binary DOM tree structure and to transmit the DOM tree structure to the client 10.
The client 10 is further configured to render the content of the DOM tree structure on the page after receiving the DOM tree structure from the proxy server 20.
The proxy server 20 includes: a URL receiving module 21, a page request module 22, and a compiling and transmitting module 23. The URL receiving module 21 is configured to receive a URL from a client and to notify the page request module 22. The page request module 22 is configured to request a page from an Internet server corresponding to the URL. The compiling and transmitting module 23 is configured to compile the script code of the page returned from the Internet server into a binary bytecode and to transmit the binary bytecode to the client.
Preferably, the compiling and transmitting module 23 is further configured to: receive a HTML file of the page returned from the Internet server after the page request module 22 requests a page from the Internet server, convert the HTML file of the page into a binary DOM tree structure, and transmit the binary DOM tree structure to the client.
The client 10 includes: a URL transmitting module 11, and a receiving and executing module 12. The URL transmitting module 11 is configured to transmit a URL requested by a user to a proxy server. The receiving and executing module 12 is configured to receive a binary bytecode transmitted by the proxy server and execute the binary bytecode. The binary bytecode is obtained by the proxy server by requesting a page from an Internet server corresponding to the URL and compiling the script code of the page returned from the Internet server.
The receiving and executing module 12 is further configured to: receive a DOM tree structure transmitted by the proxy server after the URL transmitting module 11 transmits the URL, and render the content of the DOM tree structure on the page. The DOM tree structure is obtained by the proxy server by converting a HTML file of the page returned from the Internet server.
The script processing method and the script processing system for a browser provided by the disclosure are described below in more detail in conjunction with the embodiment shown in
As shown in
For example, the WWW server transmits the following HTML file to the proxy server:
The complied binary DOM tree structure is shown in Table 1:
In Table 1, data “54 51 42 4C 00 01 21 08 00 00 87 66 83 OD OE 03” represents a file header, the data in the upper dotted box is the binary code data of “hello, world!”, and the data in the lower dotted box is the binary code data of the image in the img label.
Taking the image in the img label for example, the specific definition is described in Table 2.
When the client receives the binary data shown in Table 1 and performs rendering, the client draws the image at a proper position on the screen of the client according to the coordinate data and image size data provided in Table 2, to complete the rendering process, without computing the coordinate position for placing the image. Thus, the computation load of the client is reduced.
To sum up, the compilation and the execution of the browser script code are conducted separately in the disclosure, which is that the browser script code is compiled into a binary bytecode on the proxy server before being transmitted to the browser client of the mobile terminal, and the browser client of the mobile terminal directly executes the binary bytecode compiled by the proxy server. With such process, the overhead of script code compilation on the mobile terminal browser is reduced, and the mobile terminal browser is enabled to support the execution of script code. It should be noted that the script processing method and the script processing system for a browser provided by the disclosure are not only suitable for the processing of JavaScript code, but also suitable for the processing of VBScript code. Since the processing of VBScript code is similar to the processing of JavaScript code, no further description is needed here.
The above are the preferred embodiments of the disclosure only and are not intended to limit the protection scope of the disclosure.
Number | Date | Country | Kind |
---|---|---|---|
201110097899X | Apr 2011 | CN | national |
This is a continuation application of International Patent Application No.: PCT/CN2012/072452, filed on Mar. 16, 2012, which claims priority to Chinese Patent Application No.: 201110097899.X, filed on Apr. 19, 2011, the disclosure of which is incorporated by reference herein in its entirety.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2012/072452 | Mar 2012 | US |
Child | 14051230 | US |