Home > Backend Development > PHP Tutorial > How to correctly implement PHP website optimization_PHP tutorial

How to correctly implement PHP website optimization_PHP tutorial

WBOY
Release: 2016-07-15 13:32:19
Original
905 people have browsed it

There are many things that need to be taken into consideration when building a website. For example, if a website develops for a long time and continues to grow in scale, can its code program support the rapid operation of the website's data? Below we will introduce

1. Remember to help the page lose weight

When we browse the web, we actually download the web content in the virtual host to Local hard disk, then use the browser to interpret and view. The speed of downloading web pages accounts for a large proportion of the display speed. Therefore, the smaller the space occupied by the web page itself, the faster the browsing speed will be. This requires that you follow the principle of simplicity when making web pages, such as: do not use too large Flash animations, pictures and other resources. A clean, concise page will give people a sense of clarity of thinking.

(1) If not necessary, try to use static HTML pages

As we all know, ASP, PHP, JSP and other programs realize the dynamic interaction of web page information and run them It is indeed very convenient, because they have good data interactivity and can easily access and change the contents of the database, making the website "active", such as forums, message boards, etc. However, this type of program must first be processed by the server, generate an HTML page, and then "send" it to the client for browsing, which has to consume a certain amount of server resources. If you use this type of program too much on a virtual host, the web page display speed will definitely be slow, so there is no need, please try to use static HTML pages. For this point, please refer to http://www.routease.com/home.htm

2. Stuff the entire page content into a Table

This is web design It’s a problem. In order to pursue unified page alignment, many webmasters stuff the entire page content into a Table (table), and then use cell td to divide the layout of each "block". The display speed of this kind of website It's absolutely slow. Because the Table will not be displayed until all the content inside is loaded, if some content is inaccessible, it will delay the access speed of the entire page. The correct approach is: divide the content into several Tables with the same format, rather than stuffing them all into one Table.

3. Change access to ASP, ASPX, PHP and other files to .js references.

What we should pay attention to when optimizing PHP websites and other optimization methods is that if you want to embed dynamic data in a static HTML page, and these dynamic data are generated by ASP, PHP, etc. If provided by the program, the following statement will be used: In this case, every time a person visits your website, the server will execute and process the tongji.asp file, extract the corresponding data from the database, and then output it to the web page for display. If tens of thousands of people visit at the same time, it will be executed tens of thousands of times, and the consequences can be imagined.

It is recommended to dynamically generate data into a 1.js file in these programs, and then pass < SCRIPT src="http://www.XXX.com/1.js"> on the homepage < /SCRIPT> Code like this to reference the 1.js file. In this way, the task of data display is left to the client's browser, which does not consume server resources, and the display speed is naturally very fast.

5. Use iframe to nest another page.

If you want to insert some advertising code on the website and don’t want these advertising websites to affect the speed, then using iframe is the most appropriate. The method is: put these advertising codes into an independent page, and then use the following code to embed the page on the homepage, so that the display of the entire homepage will not be delayed due to the delay of the advertising page. The code is as follows:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span class="tag-name">iframe</span><span>   </span></span></li><li><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span>   </span></li><li class="alt"><span class="attribute">width</span><span>=</span><span class="attribute-value">"780"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"30"</span><span>   </span></li><li><span class="attribute">name</span><span>=</span><span class="attribute-value">"all"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"no"</span><span>   </span></li><li class="alt"><span class="attribute">marginWidth</span><span>=</span><span class="attribute-value">0</span><span> </span><span class="attribute">frameborder</span><span>=</span><span class="attribute-value">"0"</span><span>   </span></li><li><span class="attribute">src</span><span>=</span><span class="attribute-value">" http://www.routease.com<br />/headToolBar.jsp"</span><span class="tag">></span><span> </span></span></li>
<li class="alt">
<span class="tag"></</span><span class="tag-name">iframe</span><span class="tag">></span><span> </span>
</li>
</ol>
Copy after login

where http://www.routease.com/headToolBar.jsp is the referenced file path.

6. Pay attention to the skills of website counter code placement

Placing counters on web pages can count the website’s access traffic and provide access basis for webmasters and advertisers. However, , no matter how powerful the website statistics system is, there will be failures. If you put the statistical code directly in front of the page content, or put it in a Table or div tag, then when the counter cannot be accessed, the Table or div on your page will cause a delay of tens of seconds, causing the page Takes a long time to access. Therefore, if you want to optimize the website through PHP or other methods to improve the speed of the website, you must pay attention to the placement of the statistical code. The correct method is: put the statistical code at the bottom of the page, and do not mix it with the page content. In the same Table or div tag. You can place the statistics code directly at the bottom of the page code, or make a separate Table or div at the bottom to place the counter. In this way, your website speed will not be affected at all when the counter is inaccessible.

7. The knowledge of friendly links

Linking websites to each other can increase the publicity effect of the website. Linking LOGO pictures can more accurately describe the theme and positioning of the website, and the publicity effect will be greatly enhanced. However, too many picture links will inevitably affect the web page. display speed. Many webmasters like to directly quote the image URL on the friendship website, so that the image must be loaded first before it can be displayed. The access speed of each friendship website is different, and the entire table must wait for the image to be downloaded before it can be displayed, which greatly reduces the time consumption. Page speed. Therefore, when making friendly links, you should try your best to do the following:

1. Only make text links: making text links will not delay the speed of the web page.

2. Put all links into a separate page, and then link to the page on the homepage.

3. If the friendly link must appear on the homepage, please put the entire Table where the link is located at the bottom of the page. Because the page is displayed line by line from top to bottom, put it at the bottom of the page. Below, the display of other content will not be delayed.

4. The LOGO image of the friendly link is downloaded first and then transferred to your own web space. In this way, the speed is determined by your own web space and is not affected by the friendly website.

In short, there are many ways besides PHP website optimization, especially in the early stages of website construction, static page display + architecture should be used. Only in this way can the website access speed be fundamentally improved.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446149.htmlTechArticleThere are many things that need to be taken into consideration when building a website. For example, if a website develops for a long time and continues to grow in scale, can its code program support the rapid operation of the website's data? Next we...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template