11

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.

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
  • 1
    Consider to use Twig, you don't do much wrong choosing that template system fro two reasons: It's a good one *and* it's a friend of Assetic, both were always close. If you don't want a template language, Assetic works out of the box with plain PHP, too. It does not rely on Twig. – hakre Jun 29 '12 at 00:33
  • The Pipe project looks like it's gained some traction since this was originally posted. By the way, the URL for Pipe has been updated: [https://github.com/CHH/pipe](https://github.com/CHH/pipe) – Brent Matzelle Aug 08 '13 at 15:52
  • Hi, creator of Pipe here. What issues did you have which prevented you from getting up and running? – chh Jan 12 '14 at 17:55

1 Answers1

9

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.

chadrien
  • 498
  • 3
  • 12
  • This is ultimately what I ended up doing, but I opted to go with no template system per-say (well, I kind of rolled my own, but more or less it's just a wrapper between my controllers and a mixin for helper methods). Thanks! – Conrad Vanlandingham Dec 17 '12 at 07:48