0

I have a custom loader for my css and javascript functions.

as such.

when I am ready I have a list of css and another of javascript files.

I am looking for a way that I can then call a function and it will output a path to a compressed and combined css and js file.

so.

something like

load::css('master');
load::css('links');
load::css('buttons');
load::css();

(calling load:css() without any params should generate the minified css link)

What classes do you suggest for doing this?

4 Answers 4

0

If I understood your aim correctly Php Speedy may help you. Check it out: http://aciddrop.com/php-speedy/ .

0

It doesn't work quite the way you want, but I've found it pretty useful to use minify (http://code.google.com/p/minify/), then have a separate class (I use Zend Framework's headStyle view helper) collect all the css files I need, then build a single css/JS link that I include.

2
  • Yeah, I was looking at that, however My issue comes as, almost every page on my site uses a different combination of css and javascript files, hence, normally averaging 7 files each. I am hoping to be able to just call a minify class, and it would generate me a css/js file name based on the files. it would use some sort of alogrithm to ensure that the filename is based off the file contents and, if the js/css file exists, return is, else, create it then return it. Commented Feb 2, 2011 at 2:12
  • I had something that was pretty similar. The way minify works is that you can include a url that's something like yoursite.com/minify/?foo.css,bar.css,foobar.css as your CSS, and it will generate a minified CSS file. I had around 15 files, and it got pretty slow, but it might do the trick. Commented Feb 2, 2011 at 2:17
0

I wrote a "build" shell script for javascript and css, which I the javascript from the server, and then compress it using YUICompressor.

This wouldn't be a run-time compression like you're looking for, it'd be more of a one-time build process you do when you publish your site. My javascript is mostly static, though, so I can get away with this.

#!/bin/bash
cd /webroot/js
wget -nc -O filename.premin.js http://localhost/js/filename.src.js
java -jar yuicompressor.jar --line-break=200 -o filename.min.js filename.src.js
rm filename.premin.js
0

It sounds like the problem you're trying to solve is that you have "too many" JS/CSS files being served.

By looking for a way to merge them together, you're only compounding your problem by inventing new files that must be delivered to your clients.

Instead, learn about HTTP caching, and use it: http://www.mnot.net/cache_docs/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.