Tuesday, March 3rd, 2009
Juicer: Package your JavaScript and CSS
<p>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:
-
-
$ juicer merge file.css
-
body {
-
background: url(../images/bodybg.png?jcb=1234567890);
-
}
-
-
$ juicer merge -c hard file.css
-
body {
-
background: url(../images/bodybg-1234567890.png);
-
}
-
Related Content:











What is the use of this cache buster?
Java users can resort to Jawr for identical purposes plus several goodies such as i18n javascript or Grails integration.
Wow, that looks very interesting. Am definately going to take it for a spin soonish.
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.
I am dreaming of some kind of apache mod or framework indipendent (?) Framework for packing inline css and javascript on the fly.
@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!
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 :)