Tuesday, March 3rd, 2009

Juicer: Package your JavaScript and CSS

Category: Performance, Utility

Christian Johansen has released Juicer a very nice Sprocket-esque tool for packaging and managing your JavaScript AND your CSS.

It has taken all of the best practices and put them in one tool, including:

  • resolve dependencies for JavaScripts and CSS files
  • combine files
  • add cache busters to URLs inside CSS files
  • cycle asset hosts for URLs in CSS files
  • minify files (currently only with YUI Compressor, later others as well)
  • check syntax of JavaScripts with JsLint before they’re minifyed

The cache buster feature is quite cool. Take a look at the output of these commands:

  1. $ juicer merge file.css
  3. body {
  4.     background: url(../images/bodybg.png?jcb=1234567890);
  5. }
  7. $ juicer merge -c hard file.css
  9. body {
  10.     background: url(../images/bodybg-1234567890.png);
  11. }

Posted by Dion Almaer at 5:59 am

3.9 rating from 21 votes


Comments feed TrackBack URI

What is the use of this cache buster?

Comment by frenchStudent — March 3, 2009

Java users can resort to Jawr for identical purposes plus several goodies such as i18n javascript or Grails integration.

Comment by jordi — March 3, 2009

Wow, that looks very interesting. Am definately going to take it for a spin soonish.

Comment by MorganRoderick — March 3, 2009

You shouldn’t use querystrings to bust the cache: Revving Filenames: don’t use querystring. Proxies, including Squid, won’t cache resources with a querystring.

Comment by souders — March 3, 2009

I am dreaming of some kind of apache mod or framework indipendent (?) Framework for packing inline css and javascript on the fly.

Comment by Aimos — March 4, 2009

@Aimos: Plan is to distribute Juicer as a framework independent tool. My first idea was to package it as a standalone tool (ie with embedded Ruby). Other ideas include making some web app/tool to serve files regardless of which framework you use. Any ideas in this direction would be much appreciated!

Comment by cjohansen — March 4, 2009

icoloma: the MD5 hash idea is pretty interesting, especially where VCS modify mtime without the file being modified. I’ll consider it for sure.

About the asset hosts: If you give Juicer a spin. you’ll be pleased to note that any image will always be served from the same host when cycling several hosts. If you’ve already tried Juicer and found this not to be true, please let me know – then it’s a bug. But I do think it’s working OK :)

Comment by cjohansen — March 5, 2009

Leave a comment

You must be logged in to post a comment.