开发者

PHP Asset Packaging Library

开发者 https://www.devze.com 2023-01-21 05:28 出处:网络
anyone know a great asset management/packaging library for PHP making asset (images, cs开发者_如何学Gos, js) deployment and optimization super easy much like Jammit for Rails.I don\'t know of any inte

anyone know a great asset management/packaging library for PHP making asset (images, cs开发者_如何学Gos, js) deployment and optimization super easy much like Jammit for Rails.


I don't know of any integrated ones, but you can probably start off by combining JSMin and CSSMin into one for javascript and CSS files accordingly.

Regarding images, I'm not sure how you want to optimize them. Something like 75% JPEG compression?


I have been using Apache ant to build my minified versions of CSS and JS, it's also quite handy on doing other related build tasks.

My build.xml looks like this:

 <concat destfile="global.concat.css" fixlastline="yes">
  <fileset file="skeleton/stylesheets/base.css" />
  <fileset file="skeleton/stylesheets/skeleton.css" />
  <fileset file="skeleton/stylesheets/layout.css" />
  <fileset file="global.css" />
</concat>

<exec executable="java">
  <arg value="-jar" />
  <arg value="/usr/bin/yuicompressor.jar"/>
  <arg path="global.concat.css" />
  <arg value="-o" />
  <arg value="global.min.css" />
</exec>


About a Year ago i wrote a little library called Packtacular.

To be honest if I look at it now there is alot of stuff i would do diffrent today.

The good thing about it is that its really simple to use. You can basically just tell Packtacular a path that contains files and it will merge them together and take care if one of them changes (Wich does make deployment pretty easy too).

Packtacular::css( 'assets/css/', 'cache/stylesheet_:time.css' );

In that example it will take all .css files inside assets/css/ and merge them into one file under cache/stylesheet_:time.css. :time represents the timestamp of the "newest" file. Means you want have trouble with browser cache.

Compression or optimisation of the assets you have to implement by your own using filters:

Packtacular::filter( 'css', function( $data ) 
{
    // do some cool stuff with $data
    return $data;
});

If your looking for something simple based on PHP it might work for you. But if need something more I would suggest using Grunt or Assetic.

0

精彩评论

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

关注公众号