If you want to improve the loading speed of web pages, how to optimize it is a question. Yahoo once made an optimization with 36 items. In fact, there are many ways to optimize web pages. Here are some ways to reduce page size to improve front-end loading speed:
PHP compresses html web page code (remove spaces, newlines, tabs, comment marks).
A good way is to compress HTML. Compressing HTML actually means: clearing newlines, clearing tabs, and removing comment marks. The role it plays cannot be underestimated.
Now provides PHP compressed HTML function. Please give it a try, it feels good.
No more nonsense, just go to the code:
1
2 /**
3 * Compress html: clear newlines, clear tabs, remove comment marks
4 * @param $string
5 * @return Compressed $string
6**/
7 function compress_html($string) {
8 $string = str_replace("rn", '', $string);
//Clear newlines
9 $string = str_replace("n", '', $string);
//Clear newlines
10 $string = str_replace("t", '', $string);
//Clear tab characters www.2cto.com
11 $pattern = array (
12 "/> *([^ ]*) *",
//Remove comment mark
13 "/[s]+/",
14 "//",
15 "/" /",
16 "/ "/",
17 "'/*[^*]**/'"
18 );
19 $replace = array (
20 ">\1<",
21 " ",
22 "",
23 """,
24 """,
25 ""
26 );
27 return preg_replace($pattern, $replace, $string);
28 }
29 ?>
Eliminate line numbers
Excerpted from Xiaohanzi