I know that there are ways to dynamically load it into the page, but if I want to compress my code so it loads even faster, how do I do it?
|
|||
|
I highly recommend Google Closure Compiler for compressing JavaScript code. I use it personally, and it is also the official compressor used by the jQuery project. This project can do quite a lot, but the basics are this:
|
|||
|
I use Justin Etheredge's SquishIt project. It is awesome! For asp.net only however.
Read the intro to squishit blog post. Here's some sample code that will render a single
|
|||||
|
Add all your javascript to a single file and compress it with for example jsmin(http://www.crockford.com/javascript/jsmin.html). Do this as well for your CSS but use another compression technique (removing whitespace). Since this is a boring repeating task there are scripts available that will do just this for you. I use Django and use django-assets to fully automate this process. |
|||
|
Use gzip. |
|||
|
There are several very popular tools for compressing/minifying your JavaScript and CSS.
All are very powerful -- you can find comparisons of them quite easily. All are command line tools, so they can be easily integrated into your run automatically when you build or publish your website. You can also find many websites that run these tool for you, which will save you the time of having to install/configure. This also helps if you aren't familiar with using command line tools. Personally, I've always used YUI Compressor. |
||||
|
Check this comparison of JS & CSS minifiers to pick what suits you best - |
|||
|
This one uses YUI compressor algorithm: |
|||
|