Gzip CSS files với PHP

Nếu các bạn cũng muốn áp dụng kỹ thuật này cho website của mình, thì chỉ việc copy đoạn code sau vào bên trên trang web.
- ob_start('ob_gzhandler');
- }
- header ("content-type: text/css; charset: UTF-8");
- header ("cache-control: must-revalidate");
- $offset = 60 * 60;
- $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
- header ($expire);
- ob_start("compress");
- function compress($buffer) {
- // remove comments
- $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
- return $buffer;
- }
- // list CSS files or JS to be included in the Gzip
- include('global.css');
- include('style.css');
- if(extension_loaded('zlib')){
- ob_end_flush();
- }
0 nhận xét:
Đăng nhận xét