web| Data | database | page | Optimization with the development of the Internet, the application of Web database is more and more, and the user's speed of accessing the Web Database page is more and more high. The speed of accessing a Web page depends on the speed of the network, the performance of the server on the Web page, and the design of the Web page itself. This paper introduces a method to optimize the Web database page based on the author's years of experience development.
Solution principle
When a user accesses a static Web page, the Web server simply passes the page back to the user's browser, which is interpreted by the browser, and when the user accesses a "dynamic" Web page (with a server-side executor), the Web server needs to explain the execution of the page first. The server-side execution code that is embedded in the page is executed on the server side, and the execution results form a "static" Web page that is passed back to the user's browser and interpreted by the browser.
In the Web database application system, when the user accesses the Web database page, the Web server needs to exchange information with the database server, read the data dynamically from the database and form a "static" Web page to return to the user's browser, and then explain the execution by the browser.
Based on the above process of Web page execution, if the "read data from the database" is executed only once and a "static" HTML snippet is inserted, inserting the code into a page that needs to be read dynamically from the database can reduce the cost of accessing the database, thereby increasing the speed of accessing the page, The principle is similar to a compilation of a program, multiple executions.
Programming instances
The following take the train booking system as an example to illustrate the specific implementation of the method. The data of station name, train number, station and parking time are designed and stored in the database in the railway reservation system. Due to the increase or decrease of the train and station name, parking time changes and other information will not change frequently, with relative stability, so you can change the data needs of the system administrator at a time to execute a piece of code, from the database to extract data and generate a number of HTML code "static" reference files for the need for station name, train, docking station , parking time for each web page reference. Only when the next railway system adjusts the time, the number of trips and other information, the system administrator is necessary to modify the data in the database, regenerate and overwrite the original HTML code "static" reference file, and the "Static" code to refer to the various web pages without any modification.
The following is an example of "station name", which describes the generation of "static" code and how each Web page refers to this "static" code. Set the system to use Access database Train.mdb, table name is Tab_train, "Station name" field is stations. First read the "station name" from the database and generate the "static" HTML code of the ASP program, and then save the generated "static" code in the file Stations.inc.
/*make_stations.asp*/
<%
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
FilePath = Server.MapPath ("Station.inc")
Set file = fso. CreateTextFile (FilePath)
Set conn = server. CreateObject ("ADODB.") Connection ")
DBPath = Server.MapPath ("Train.mdb")
Conn. Open "Driver={microsoft Access driver (*.mdb)}; Dbq= "& DBPath
sql = "Select stations from Tab_train"
Set RS = conn. Execute (SQL)
Line = "function put_stations () {"
File. WriteLine Line
line = "Document.writeln (' &" <select name = ' stations ' > ') "
File. WriteLine Line
While not Rs. Eof
line = "document.write (' <option >" & RS ("Stations") & "</option>")
File. WriteLine Line
Rs. MoveNext
Wend
line = "document.write (' </select> ')}"
File. WriteLine Line
File.close
%>
The HTML page that references the "static" station name is as follows:
< HTML >
< head >
< title > referencing stations.inc files </title>
<!--include file= "Stations.inc"->
< BODY >
< table >
< TR >< td >
< script language= "JavaScript" > Put_stations () </script >
</td ></tr >
</table >
</body>
Summary
In the Make_stations.asp program code, the method of generating "function" is used, and the advantage of this design is that the function can be referenced in any layout position of another page. In the slightly complex Web database application system, there are some "not frequently changed, relatively stable" information, which is "static" optimization, can significantly improve the Web database access speed. Of course, query statistics pages that need to reflect the state of the current data in the database cannot be "statically" optimized.