问题
Background
I am working on "modernizing" a pre-existing PHP-driven website. This website started out as a static website with a few php methods. It now has a mobile web app, multiple models, and a lot of dynamic content. However, overtime the structure of the app itself hasn't changed much from when it was a largely static site, so now there are include files all over the place, no separation of application/presentation logic, etc etc. It is a mess to work on. So I am reorganizing everything and redeveloping a lot of the pre-existing functionality as we prepare for upcoming upgrades to the growing ecosystem. First, I am re-coding everythign to fit within an MVC architecture. Although I do work with PHP, most of my background comes from Ruby and Node, thus my question:
Actual Question
I'm rather fond of Rails' Asset Pipeline, and seeing as the current site I'm working on (see above background) has about 10 different stylesheets and even more javascript files, I'd really like to implement some sort of asset manager as I transition the site over to an MVC setup.
I've found Assetic, which seems rather interesting, but I do not quite understand the best way to implement it into a templating system (I am not using any pre-built templating such as Twig, which any reference material I can find utilizes) or have it dynamically serve assets.
I also found something called Pipe: https://github.com/CHH/pipe, which looks like a very close port of Sprockets, but I couldn't get it to properly run.
Are there any applications that implement Assetic (or Pipe), or another Asset packager that doesn't rely on an existing template engine, such as Twig, that I could look at?
Really, I'm looking for something that will minify/combine multiple JS and CSS files, and then cache them.
回答1:
Liek hakre said, Assetic works out of the box. You do not need any templating system (Twig, Smarty...) for it works.
With a templating system, Twig is the best because, like hakre said, it's strongly implemented. However, it's not that diffucult to integrate it into any other template system (I quickly wrote a Smarty plugin for personnal use, it works well).
Finaly Assetic does anything you need :
- Combine JS/CSS : done with the AssetCollection class (has show here)
- Minify : here you'll use the filters Assetic provides : CssMin, JsMin, JsMin+, Google Closure Compiler, you've got the choise. There even are image fitler for image optimization (mainly quality lossless size reduction)
- Cache : Assetic has a cache system so you don't have to create one by yourslef.
The last advantage that goes to Assetic is that it's the one used by default in Symfony2, which is, imo, one of the best PHP framework lately, so it proves that Assetic is a good choice.
Only problem I had so far using Assetic out of Symfony was the lack of documentation (the usage of the CssRewriteFilter in my case) but good understanding of the source code often helps getting how it's supposed to work.
来源:https://stackoverflow.com/questions/11254287/asset-pipeline-framework-for-php