I really don't like writing text materials, but I believe this is something that many people need. I want to share my experiences with you, so that everyone can work hard, to help you complete this stuff as soon as possible and post it for download and use as soon as possible.
Why do we need to generate a static page?
We will not talk much about this problem. There is only one advantage of it, which greatly improves the website performance. I am afraid I can't stand the solution for websites with large data volumes and large traffic volumes that do not use static page output. Let's not talk about the disadvantages, a lot .... However, this advantage alone deserves our research. Next we will discuss the conventional processing methods of the static page generation scheme and the flexible Processing Methods of staticpol to compare them.
Reasons for saying that he is a platform:
Conventional method: In eachProgramWrite the corresponding module (Program) for generating static pages, execute corresponding updates, and generally perform manual updates (Home Page, category page, and information page). This is troublesome, even if it is a regular update, you also need to write the corresponding program for execution.
Staticpol: It runs independently on ASP. net, but can be ASP, PHP, Asp.. net, JSP, and other programming languages provide the corresponding static page generation service to provide the corresponding static page solution.
The reason for saying that he is the ultimate solution:
Conventional method: Either write programs for batch update or update when adding, modifying, or deleting programs. The former is just a waste disposal method, but many people are still using it. The latter is better, but the program is very rigid, any configuration changes involve program changes.
Staticpol: static page generation and update occur during user access (if a user does not access the page, it is not generated because the page is generated ), in addition, page updates are controlled by policies without manual participation. That is to say, you only need to define the update policy, and the rest will be completed by staticpol. Generation during user access can save a lot of I/O operation resources, and policy management updates can almost synchronize with dynamic management functions, so I call it the ultimate solution.
Now, let's briefly introduce the execution principle of staticpol:
Staticpol consists of two aspx files.
Index. aspx: used to process the 404 error page.
Updatestaticfile. aspx: Used to update policies for page generation.
Web. config: stores system configuration information and static update policy information.
The following is the configuration information of my official static update policy:
<! --
Static Page Generation Policy
Makefilepath: static page address rules
Lookfor: the rule used to generate the dynamic page address of the Static Page
Updatepolicy: rules generated on this page
◎ None: no operation
◎ Handwork: Manual (compared with the last update time of the system)
◎ Timespan: Time Difference
Lastupdatetime: The Last Update time used by this policy (valid only when updatepolicy is handwork)
Updatetimeurl: Get the last update time used by this policy from the specified URL (only valid when updatepolicy is handwork)
Timespan: time difference between updates (in minutes, only valid when updatepolicy is set to timespan)
-->
<Staticpolconfig>
<Rules>
<Polrule remark = "Homepage">
<Makefilepath> ~ /([-_, A-Za-z0-9] +) \. html </makefilepath>
<Lookfor> ~ /$1. aspx </lookfor>
<Updatepolicy> timespan </updatepolicy>
<Timespan> 10 </timespan>
</Polrule>
<Polrule remark = "information page">
<Makefilepath> ~ /Index/catalog (\ D +)/(\ D +) \. html </makefilepath>
<Lookfor> ~ /Index/CATALOG $1/$2. aspx </lookfor>
<Updatepolicy> handwork </updatepolicy>
<Updatetimeurl> ~ /Index/CATALOG $1/$2. aspx/lastupdatetime </updatetimeurl>
</Polrule>
<Polrule remark = "other pages">
<Makefilepath> ~ /Index/([-_, A-Za-z0-9] +) \. html </makefilepath>
<Lookfor> ~ /Index/$1. aspx </lookfor>
<Updatepolicy> handwork </updatepolicy>
<Lastupdatetime> 10:50:30 </lastupdatetime>
</Polrule>
</Rules>
</Staticpolconfig>
Next we will introduce the execution process. We take IIS as an example. First, we will customize the index in staticpol for the website's 404 error page. aspx, then we access this address http://www.seaskyer.net/Index.html, this file by default for the first access is certainly not exist, IIS will automatically forward to the 404 error page for processing, that is, the index just set. ASPX page, at this time he began to check whether there is a matching path in the policy configuration, detected that the first match, so the http://www.seaskyer.net/Index.html is matching the address http://www.seaskyer.net/Index.aspx, on the 404 error page, the content in the downloaded http://www.seaskyer.net/Index.aspx is processed and saved back to the static path ~ /Index.html, obviously the directory is under the root directory of the website, and then use the script window. location. reload (). At this time, the file index.html already exists, so you can directly access the static page file without processing the 404 error page. After that, the static page index.html will be accessed by another user.
We can also see from the configuration that it is updated every 10 minutes, so how does it automatically update?
The principle is also very simple. while generating the static page, we inserted a script in that page, such as: <script language = "JavaScript" src = "/staticpol/updatestaticfile. aspx? Requestedpath =/index.html "> </SCRIPT>, as mentioned earlier, updatestaticfile. the aspx file is used to update the policy of the generated page. How is it updated. In the same way, you can obtain the processed page by passing the parameter value requestedpath, and then check whether there is an update policy, after passing the path, it is detected that the first policy complies with the path. By detecting the file index.html modification time and the current time, if the content is updated within 10 minutes, the page is not updated as long as it is within 10 minutes.
This is basically the principle of others. It may not be detailed yet, so I will paste some images later.CodeIt's okay to come up. I'll write it here today, and I'll make up later.
At present, my official station: http://www.seaskyer.net/(Haitian people) is using this solution. Let's take a look at this demonstration.
Sometimes the code below does not know where to put it. Here is a note :)
D: \ staticpol