[Catalyst] Minify JS/CSS and server as static files

Bill Moseley moseley at hank.org
Mon Aug 8 05:05:08 GMT 2011


On Sun, Jul 31, 2011 at 9:17 PM, Pavel Karoukin <hippich at gmail.com> wrote:

> Hello,
>
> I am looking to develop feature in my project but want to check if
> something already exists or there is existing pattern to implement it.
>
> Bassically, I want in my TT templates add JS/CSS files into header. And
> in production mode I want minify/aggregate 'em and save on disc so web
> server could serve these minified and aggregated files directly.
>
> How I plan to do it:
>
> In TT layout template define array variable and all templates will be
> adding there JS/CSS they need. Then in main template I will generate
> code like:
>
> <link rel=3D"stylesheet" type=3D"text/css"
> href=3D"/minify/css?files=3Dpath/to/file1.css;path/to/file2.css" />
>


What I do is define a YAML file that defines "resource sets" (where a
"resource" is anything I want to serve differently in production, like css,
javascript and even versioned items like background images or PDFs).

For example, a set might be defined of one or more (typically more) css
files.  The set has a name (e.g. "style") and then in my templates I use a
macro to include it.  Under development the markup is rendered with the
individual css files that make up the set.  Under production the markup
includes a link to a single minified and versioned versioned URL (on a CDN).
  We can also easily toggle this on production via request data (to debug on
production someone wanted).  The versioning is done via an md5 of the
compressed file and the minified files are cached forever.

The build process runs a script that builds the minified files.  I've often
though about trying to integrate it into the Makefile so that only changed
source files trigger a build of the minified file.



>
> /minify/css will be action of controller minify to join and minify these
> files and save them in /static subfolder as single file. Then I need to
> configure webserver somehow to look for this file (good question - how
> to do it...) and serve it directly instead of firing catalyst action.
>
> Few problems tho:
> 1) How to name files to keep track of: list of files in minified file,
> their update date.
> 2) How to remove old files. (probably with cron?)
>
> Any ideas will be really appreciated!
>
> Regards,
> Pavel
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110808/b85f1=
02c/attachment.htm


More information about the Catalyst mailing list