CoffeeScript directly in the browser
Most of the time, we should compile CoffeeScript to JavaScript before serving it to a web browser. This provides much better performance and is guaranteed to work well across all browsers. However, it is possible to run CoffeeScript code directly in the browser! This magical feat is accomplished by sending a special version of the CoffeeScript compiler code to the browser, which may then be used to parse and compile CoffeeScript into JavaScript, and run it.
Note
This is thanks to the fact that the CoffeeScript compiler is itself written in CoffeeScript! So we can use the CoffeeScript compiler to compile itself into JavaScript! Is your mind blown yet?
We can add this ability right to our pet shop application. We need to download a standalone version of the CoffeeScript compiler. It's available from the CoffeeScript site: http://coffeescript.org/extras/coffee-script.js. We'll put this file in our main application directory. Now we'll include this library in...