开发者

PHP - JS and CSS minifier [closed]

开发者 https://www.devze.com 2023-04-05 04:18 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. 开发者_开发技巧Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.
开发者_开发技巧

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 9 years ago.

Improve this question

I have a simple CSS minifier which... all it does is removes whitespace and comments. I'm rather happy with it but if there is something better - let me know.

Now for JS minifiers, I have this beast of a thing here: https://github.com/rgrove/jsmin-php/blob/master/jsmin.php of course, I have some pretty long JS scripts. I want something long, to minify rather quickly. Minifying jQuery (I know it's already got a minified) takes 2 seconds, sometimes even 4 or more! I won't have files as large of jQuery, but I may get some half as large and I doubt 1-2 seconds to load a single JS file is very attractive.

I'm wondering if there is some quick minifiers out there? I only need a minifier, I don't need something that combines, caches etc.


You do not need a quick minifier - just build (minify) new version of your javascript when you do changes and save it all into js file


<?php
$js = file_get_contents($_GET['f']);
$md = md5($js); // you can use sth faster, such as date comparsion
if (file_exists('cache/'.$md.'.js')) {
  echo file_get_contents('cache/'.$md.'.js');
} else {
  $min = yourJsMinifierFunc($js);
  file_put_contents('cache/'.$md.'.js', $min);
  echo $min;
}

Ok, it should work for you. Once you modify your .js file, it's being minified and cached.


I suggest you to have a look at Assetic library. With Assetic you can manage from PHP side all of your assets applying filters as you need

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号