bookmark

How do I compress my JavaScript code?


Description

How do I compress my code?

Generally the best way to do it is to use the YUI compressor.

An alternative is to use Douglas Crockford's JSMin. This doesn't compress JavaScript code as small, but generally how you write your code matters less. jQuery also provides a pre-minified version of jQuery for your convenience.

Packing javascript using Dean Edwards' Packer (specifically using the base64 encode) is not recommended, as the client-side decoding has significant overhead that outweighs the file-size benefits.

If compressing your JavaScript breaks it, try running the code through JSLint. This will detect minor errors that can cause packed JavaScript to fail where the unpacked version works fine.

Preview

Tags

Users

  • @flori

Comments and Reviews