News for hackers. Stuff that matters.

Ask YC: Any risks with JS and CSS compression?

We are in final stages of finalizing our code for our open alpha. I am researching ways to improve the page load time and am looking at http://webjackalope.com/fast-page-load-time/

The article suggests to compress JS and CSS files, and I am feeling that we should compress our javascript files because we have lots them.

What worries me though is if something will break. Even if we try to test again, the application has lot of functions and testing would take time and at this moment I need to concentrate on hosting setup than application testing.

I've never done it, so want to understand the risks involved. Also if you can suggest best compression tools that would be great.

Thanks in advance,

( 7 comments | 4 points | on HN )
Re:Ask YC: Any risks with JS and CSS compression? by qhoxie on Tuesday August 26, 2008 @03:12AM (#286837)
There aren't really any risks involved aside from the fact that most (all?) compressors expect well-formed scripts, and thus can break ones that don't meet standards.

A common way to do compression that will give you a similar effect is to gzip content from the web server.

Re:Ask YC: Any risks with JS and CSS compression? by prashantdesale on Tuesday August 26, 2008 @03:23AM (#286852)
Thanks a lot.
Re:Ask YC: Any risks with JS and CSS compression? by nostrademons on Tuesday August 26, 2008 @09:37AM (#287047)
In particular, most compressors are picky about semicolons. If you use JavaScript's implicit line breaking, they'll break. This includes function definitions: there should be a semicolon after each function definition, something that most JavaScript programmers forget.

I find that using JSMin + GZip (on the webserver level) compresses just as well and tends to break fewer things.

Re:Ask YC: Any risks with JS and CSS compression? by dhotson on Tuesday August 26, 2008 @03:36AM (#286862)
One thing that has bitten me a couple of times is that CSS compression can muck up your styles if you depend on the order of the CSS rules. Compression will sometime change the order of the rules.
Re:Ask YC: Any risks with JS and CSS compression? by nickb on Tuesday August 26, 2008 @03:22AM (#286850)
Minify JS, don't compress it. Same goes for CSS compression tools. They all have a potential to give you soooooooooo many headaches for very little gain. Instead, enable gzip compression.
Re:Ask YC: Any risks with JS and CSS compression? by ionfish on Tuesday August 26, 2008 @07:54AM (#286974)
Try PackR for your JavaScript (and then gzip it, obviously).

http://github.com/jcoglan/packr/tree/master

Re:Ask YC: Any risks with JS and CSS compression? by prashantdesale on Tuesday August 26, 2008 @12:15PM (#287209)
Thank you everyone for your feedback.