Tips on page optimization and pseudo-static _ php

Source: Internet
Author: User
Page optimization and pseudo-static descriptions. About page optimization and pseudo-static

1) layout optimization
2) pseudo-static (focuses on apache, smarty, and regular expressions)

Details:

I. layout optimization:
Layout Optimization mainly involves the relationship between HTML, JS, CSS, and XML (XML correlation is not described here ).
1) In general, on the premise of resource sharing, our most basic goal is to include search engines (many people are confused by AJAX and use AJAX everywhere, but my opinion is, only in the background or user operations ).
Therefore, we should first design based on the search engine indexing rules (in fact, the "pseudo-static" mentioned below is not for the search engine, because the relevant documents have several pages, please search by yourself ), the main problem is the use of html, such

2) then solve the loading speed and content purity problems:
The main principles are as follows:
1> do not add unnecessary HTML to make the layout beautiful. we recommend that you hand over the beautiful layout task to CSS and carefully consider the reusability of CSS, HTML is only used to describe the information content (it seems to be the focus of XML ). I checked some websites on the internet. good websites and html accounts for less than 50% of the total content, but some sites and text accounts for less than 20% of the total content,
2> write JS and CSS as files. as long as the CAHCHE of the browser is used, content downloading is reduced.
3> HTML tags should be nested as much as possible. I have seen an exaggerated site where TABLE nesting is actually layer 11... crazy sweat ....

3) reasonable data processing time
This involves a lot of content, mainly

II. pseudo-static
Here we mainly describe the application of apache and smarty. of course, it doesn't matter which template is used or even not used. it's just that I have been using smarty for many years and feel its strength deeply.
This part focuses on users who have control over the system and are familiar with apache and regular expressions.

Here, the core is to emphasize the application of regular expressions. if you do not use regular expressions, you can only stay in the same plagiarism stage and even cannot use them. in addition, regular expressions are common in applications (basically in all languages), frequently and powerful. I suggest you spend some time learning them well and enjoy them for the rest of your life.
For search engines, the key is to process "?" in GET "?" , "&". "Php", and the question of URL length is OK. The form depends on your hobbies.
Let's Talk About APACHE first. The key is to use mod_rewrite to open the mod_rewrite module (in httpd. conf, remove "#" before LoadModule rewrite_module modules/mod_rewrite.so)

If vhost () is used, you can add the following code in the vhost:

RewriteEngine On
RewriteCond % {HTTP_HOST} ^ xxx.com $
RewriteRule ^/([^ \. \/] +) \. html $/index. php? Action = $1 [L]

Explanation:
The above configuration may not be placed in the vhost, as per your personal requirements.
The first line indicates that the vhost will use rewrite (URL rewriting)
In the second row, RewriteCond is used to execute the following RewriteRule command if the following conditions are met (the first parameter satisfies the second parameter, and the second parameter is a regular expression, % {xxxx} indicates the apache variable, and % {HTTP_HOST} indicates the URL host (domain name). for other variables, see apache2 manual.
The third line implements url rewriting. The first parameter is the url entered in the browser. only the uri that meets the regular expression can be rewritten. The second parameter is the rewrite rule, that is, convert the url that meets the first parameter to the url you need according to this rule. here, the author must point out that if the rewritten url contains "http ://", the redirected address is displayed in the address bar of the browser. The third parameter is some control. for example, the preceding [L] indicates that the rewrite is the last one, and the subsequent rewrite rules are no longer executed.

Smarty:
It is mainly used to process the output page content. after you use apache rewrite, the link on your page certainly uses its rules. for example: it was originally abc. php? Action = doit should use a way like abc/action-doit.html, of course, you can manually modify the page, but I think this is a stupid way. why not use ob_xxxxx () for control? (For use of ob_xxxx () functions, refer to the php Manual). here we will use smarty to replace it, because it will be more flexible.
In smarty, use register_outputfilter () to register a processing method. the specific method is as follows:
// Define a processing function first
Function change_url ($ tpl_output, & $ smarty)
{
$ Tpl_output = preg_replace ("// index. php? \? Action = ([^ &] +)/I ","/\ 1.html ", $ tpl_output );
Return $ tpl_output;
}
// The first parameter of this function is the content of the smarty page, and the second parameter is the smarty pointer.
// Then use
$ Tpl-> register_outputfilter ("change_url ");

The register_outputfilter () method is the output filter function, that is, the first parameter assigned to change_url ($ tpl_output, & $ smarty) is the page content processed by smarty.
The former filter method register_prefilter () is also used for the same type, that is, the smarty template is handed over to the first parameter. for detailed usage, see The smarty manual.

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.