Static Page Management and Maintenance for dynamic websites

Source: Internet
Author: User
Tags website server

Summary:

Static webpages and dynamic webpages have their own characteristics. The use of dynamic webpages or static webpages mainly depends on the functional requirements of the website and the content of the website. If the functions of the website are relatively simple, the amount of content updated is not large, the use of pure static Web pages is simpler, and dynamic web pages are generally used.

Static webpages are the foundation of website construction, and there is no conflict between static webpages and dynamic webpages. To meet the search engine search needs of websites, even if dynamic website technologies are used, you can also convert the webpage content to a static webpage for publishing.

Dynamic websites can also adopt the combination of static and dynamic web pages. Dynamic Web pages are suitable for dynamic web pages. If it is necessary to use static Web pages, you can consider using static Web pages, on the same website, dynamic and static webpage content also exists.

I. Dynamic and Static webpages

What is a dynamic web page? What are the characteristics of dynamic web pages?

Dynamic Web Pages correspond to static Web pages. Also, the URL extension is not .htm?.html=.shtml ,. XML and other common forms of static Web pages, instead. ASP ,. JSP ,. PHP ,. perl ,. CGI and other forms are suffixed, and there is a symbolic symbol in the dynamic Web site-"? ".

If the page url is: http://www.webjx.com/list.php? Typeid = 3

This is a typical form of Dynamic Webpage URL.

The dynamic web pages mentioned here are not directly related to the visual "dynamic effects" of various animations and subtitles on the web pages. Dynamic Web pages can also be pure text content, it can also contain a variety of animation content, which is only the form of the specific content of the webpage, regardless of whether the webpage has a dynamic effect, the web page generated by using dynamic website technology is called a dynamic web page.

From the perspective of website viewers, basic text and image information can be displayed on both dynamic and static pages, however, from the perspective of website development, management, and maintenance, there is a big difference.

The general features of dynamic web pages are summarized as follows:

(1) dynamic web pages are based on database technology, which can greatly reduce the workload of website maintenance;

(2) websites using dynamic web technologies can implement more functions, such as user registration, user logon, online surveys, user management, and order management;

(3) A dynamic webpage is not a webpage file that exists independently on the server. The server returns a complete webpage only when the user requests it;

(4) "?" in a dynamic webpage There are some problems with search engine search. Generally, it is impossible for search engines to access all webpages from a website database, or for technical reasons, search Spider does not crawl the "?" in the website Therefore, when using dynamic web pages for search engine promotion, some technical processing is required to meet the search engine requirements.

(5) websites have great security risks due to their interactivity. if the security of the website is not taken into account by developers during programming, the website is easily hacked.

(6) Information on pages of a dynamic website must be read from the database. Each time a page is opened, the database is read once. If there are many visitors to the website, this will increase the load on the server and affect the speed of the website.

What is a static webpage? What are the characteristics of static Web pages?

In website design, web pages in pure HTML format are often referred to as "static Web pages". Early websites were generally made from static Web pages.

Static web pages are typically in the form of: http://www.webjx.com/htmldata/2005-06-17/1118962699.html

It is also suffixed with .htm=.html#.shtml and. xml. Dynamic effects can also be displayed on HTML-formatted web pages, such. animated GIF, Flash, and scroll letters. These "dynamic effects" are only visually different from the dynamic web pages described below.

The characteristics of static Web pages are summarized as follows:

(1) every webpage has a fixed URL, and the URL of the webpage is suffixed in common forms such as .htm?.html=.shtml, but does not include "?";

(2) once the webpage content is published to the website server, the content of each static webpage is stored on the website server, no matter whether there are users or not. That is to say, static web pages are files actually stored on servers. Each web page is an independent file;

(3) The content of static Web pages is relatively stable and therefore easy to be searched by search engines;

(4) static Web pages do not support databases and have a large workload in website production and maintenance. Therefore, it is difficult to rely solely on static Web page production when the website information volume is large;

(5) interactive interaction between static Web pages, which imposes great functional limitations.

The concepts and features of dynamic and static Web pages are described above. The above information shows that when the website size is small and the content of the website is not updated frequently, it is perfect to use static pages. However, when the website content is updated frequently, the use of static pages is not easy to update, so using dynamic pages will save a lot of effort. However, dynamic pages also have their own shortcomings,ProgramThe amount of data to be processed is very large, which may cause website instability or even paralysis. There is a solution to the above problems, that is, to manage website information by combining Dynamic and Static resources. The so-called "Dynamic and Static combination" means that the published content is recorded in the background program. After the input is complete, the background program automatically creates static webpages Based on the selected templates and stores the entered information on the server. The management and maintenance of these static webpages are also carried out by the background program in a unified manner, human intervention is not required. This avoids the heavy workload of manual creation of static pages, without losing the flexibility of dynamic pages.

Ii. static dynamic pages

Taking the news publishing system as an example, there are two situations that need to be analyzed.

First, a page with little content changes after the information is published (for example, a news display page ). This type of page does not change much after it is released, so you can use the background for management. Specific operations include: addArticleGenerate static pages, update static pages when modifying articles and managing comments, and delete static pages when deleting Articles. Because the article links direct to static pages, and user browsing does not need to be processed by the program, the browsing speed is the fastest. However, the disadvantage is also obvious. Static pages cannot be automatically updated after they are generated. The administrator needs to perform manual operations in the background, which is particularly inconvenient during the revision.

Second, after the information is published, the page content changes greatly (for example, the news list page ). Such pages change frequently with the addition, modification, and deletion of published information. An article is added. the category of this article and the category list page of all its parent categories need to be updated. This process has a great impact on server performance, in addition, the generated static page may not be accessible. To solve this problem, a dynamic page on the front-end can be involved in static page management and maintenance. The front-end workflow is as follows: all classification page connections point to a dynamic page (for example, class. aspx? Classid = 123 & page = 1, classid is the ID of the category, page is the page number), this page checks whether the corresponding static page exists or needs to be updated, if it does not exist or needs to be updated, then, it is updated and then switched to the corresponding static page. The background design is relatively simple. You only need to delete all static pages of the sub-category and parent category when the article is added, modified, or deleted. The advantage of doing so is that you can avoid generating inaccessible pages, which reduces the burden on the server and automatically update pages on a regular basis. On the other hand, the front-end still relies on the process order for maintenance, when the traffic volume is large, it is still a huge burden on the server.

Iii. Specific design

First, use Asp.net and C # to describe how to generate static pages. By using the httpwebrequest class, dynamic web pages can be easily static. ProgramCodeAs follows:

Public bool string makestatic (string Surl, string htmlpath)

{

Try

{

String sresponse = NULL;

// Send an http get request Surl

Httpwebrequest request = (httpwebrequest) webrequest. Create (Surl );

Stream stream = request. getresponse (). getresponsestream ();

Using (streamreader reader = new streamreader (stream, encoding. Default ))

{

// Read Server Response

Sresponse = reader. readtoend ();

Reader. Close ();

}

Using (streamwriter writer = new streamwriter (htmlpath, false, encoding. Default ))

{

// Write the Static Page

Writer. Write (txt );

Writer. Flush ();

Writer. Close ();

}

}

Catch

{

// Failed

Return (false );

}

// Succeeded

Return (true );

}

The makestatic function receives two parameters. Surl is the page to be viewed, and htmlpath is the static file to be saved. This function simulates the browser, sends an http get command to the server, requests the address Surl, receives the HTML code returned by the server, and saves the HTML code to the htmlpath file, it completes the creation of static pages.

Next, we provide specific solutions for the first two cases.

The first case is the news display page.

The above functions can be used to generate static pages easily. However, there are several practical problems to solve. After a static page is generated, the content is fixed. to automatically update advertisements, clicks, and comments, the content cannot be put into the static page, instead, the framework or script is used to include static pages. Such a part does not affect each other and is easier to update.

I. Advertisement updates. Directly use a framework to include a page containing advertisements (for example, ad.html] can be fully resolved, and only ad.html can be updated when advertising is changed. The content of all static pages will be updated. Framework code:

2. Click volume update. Like advertising, the idea is that there is a separate page to count clicks (for example, hits. aspx), you can use the Framework to include the static page (the code is the same as above), or you can use the script method, the code is:

The Code provides a parameter named ArticleID, which specifies the Document ID of the clicks to be updated. Hits. aspx updates the clicks of the article based on the ArticleID parameter and outputs the output.

3. Update comments. The update process of comments is complicated because adding comments is an interactive process and static pages cannot complete this operation. The solution is to hand over the comments to another page (for example, remark. aspx. The specific process is: use form to remark the static page. aspx transmits the content of the comment, remark. aspx receives comments, adds comments, updates static pages of an article, and redirects to static pages. In this way, the comment is added.

Code in form:

Comment:

Code for related operations in remark. aspx:

Protected override void onload (eventargs E)

{

Base. onload (E );

Int narticleid = int. minvalue; // Article ID

Int nclassid = int. minvalue; // category ID

Try

{

// Obtain input parameters

Narticleid = int. parse (this. Request. querystring ["ArticleID"]);

Nclassid = int. parse (this. Request. querystring ["classid"]);

}

Catch

{

}

// Check validity

If (narticleid <1 | nclassid <1)

{

This. response. Redirect ("/error.html", true );

}

String sremarkbody = This. Request. Params ["remarkbody"];

// Format:/show. aspx? Id = 456 & cid = 123

String sfrom = string. Concat ("/show. aspx? Id = ", narticleid," & cid = nclassid );

// Format:/news/123/456 .html

String sto = string. Concat ("/news/", nclassid, "/", narticleid, ". html ");

If (sremarkbody! = NULL & sremarkbody. length> 0)

{

// Add comments

Insertremark (narticleid );

// Generate a static page

Makestatic (sfrom, this. mappath (STO ));

}

// Turn to the static page

This. response. Redirect (STO, true );

}

The static pages processed in this way are exactly the same as other static pages during normal browsing, but they only treat the updated comment program during comments. The overall reception speed is still very fast.

The second case is the news classification list page. This type of page changes greatly when managing news, and it is inconvenient to use background management. This requires some programs to help administrators manage these pages. The program idea has been mentioned earlier, and the program code that can be applied is provided here.

Protected override void onload (eventargs E)

{

Base. onload (E );

Int nclassid = int. minvalue; // category ID

Int npage = int. minvalue; // page number

Try

{

// Obtain input parameters

Nclassid = int. parse (this. Request. querystring ("classid "));

Npage = int. parse (this. Request. querystring ("page ");

}

Catch

{

}

// Check validity

If (nclassid <1)

{

This. response. Redirect ("/error.html", true );

}

Else if (npage <1)

{

Npage = 1;

}

// Format:/list. aspx? Cid = 123 & page = 456

String sfrom = string. Concat ("/list. aspx? Cid = ", nclassid," & page = ", npage );

// Format:/news/123/default456.html

String sto = string. Concat ("/news/", nclassid, "/Default", (npage = 1 )? (""): (Npage )...

Posted onXiaoqcn reading (...) Comment (...) EDIT favorites

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.