In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to use JS and CSS optimization tools Minify". In daily operation, I believe many people have doubts about how to use JS and CSS optimization tools Minify. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use JS and CSS optimization tools Minify". Next, please follow the editor to study!
Code for merging and compressing multiple JS and CSS files
HTML:
The copy code is as follows:
PHP:
The copy code is as follows:
/ / output JS
Header ("Content-type:Application/x-javascript; Charset: utf-8")
If (isset ($_ GET)) {
$files = explode (",", $_ GET ['get'])
$str =''
Foreach ($files as $key = > $val) {
$str. = file_get_contents ($_ GET ['path']. $val)
}
$str = str_replace ("\ t", "", $str); / / clear spaces
$str = str_replace ("\ r\ n", "", $str)
$str = str_replace ("\ n", "", $str)
/ / Delete single-line comments
$str = preg_replace ("/\ s * [a-zA-Z0-9 _\ x7f -\ xff] [a-zA-Z0-9 _\ x7f -\ xff] * /", ", $str)
/ / Delete multiline comments
$str = preg_replace ("/\ * [^\ /] *\ *\ / s", "", $str)
Echo $str
}
/ / output CSS
Header ("content-type:text/css; charset: utf-8")
If (isset ($_ GET)) {
$files = explode (",", $_ GET ['get'])
$fc =''
Foreach ($files as $key = > $val) {
$fc. = file_get_contents ($_ GET ['path']. $val. ".css")
}
$fc = str_replace ("\ t", "", $fc); / / clear spaces
$fc = str_replace ("\ r\ n", "", $fc)
$fc = str_replace ("\ n", "", $fc)
$fc = preg_replace ("/\ * [^\ /] *\ *\ / s", "", $fc)
Echo $fc
}
It's just a simple prototype, no encapsulation. In addition, the merged files remember to cooperate with the cache
II. How to use Minify
1. Download the latest version of Minify from code.google.com/p/minify/ and extract it, and copy the "min" folder together with its contents to the DOCUMENT_ROOT directory (that is, websites and directories).
You can change the folder name "min"
2. Configure the g parameter in "min/groupsConfig.php"
The copy code is as follows:
Return array (
/ / 'js' = > array (' / / js/file1.js','/ / js/file2.js')
/ / 'css' = > array (' / / css/file1.css','/ / css/file2.css')
);
3. Just quote it in the web page as follows:
The following numbers can be marked with the update date, and "min" corresponds to the name in step 1.
4. For performance optimization, please refer to code.google.com/p/minify/wiki/CookBook
Note:
1. You need to enable the rewrite_module module in httpd.conf.
2. During the development process, you can turn on the debug mode, and then turn off the debug mode after the development is completed. You can use the firebug of Firefox to view it.
The copy code is as follows:
$min_allowDebugFlag = true
At this point, the study on "how to use JS and CSS optimization tool Minify" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.