Useful Rails javascript expansions for EXTJS
If you're using Edge Rails (or > 2.1, which isn't out at time of writing), and are using the EXT
If you're using edge rails you may have noticed that you can now define your own JavaScript expansions (if you're not on edge this will be included in the imminent 2.1 release). The default expansion that comes with rails looks like this:
Which grabs application.js as well as the prototype/scriptaculous javascripts and includes them all (only do that if you need it all - it adds ~150kb to your page). But say you've got a line which looks like this:
And say you want to include the same set of files on a different page - it turns out Rails makes it really easy to DRY this up. Make a new file in the config/initializers directory (I call my asset_tag_expansions.rb) and add a line like the following (don't forget to restart your server afterwards):
Now in your views you can simply put:
You can of course register as many of these as you like, and include as many of your own expansions on the same javascript_include_tag line as you want, e.g.:
The same applies to stylesheets:
Finally, although you're getting all that onto one line, each asset file is still being requested separately by your browser, each time making another nasty expensive HTTP request. Rectify that:
This bundles up your three stylesheets and concatenates them into a single file, which is called public.css in this case. In the example above this means two less trips to the server to retrieve the stylesheet files, therefore a faster loading page. This is helpful because it enables you to maintain small, targeted stylesheets in development which makes finding the relevant CSS declarations easier, without the performance hit of all those HTTP requests when in production.
One final option is to use the :all expansion, which just grabs everything in the stylesheets or javascripts directory. Be careful with that though as you've got to be sure assets are being loaded in the right order (especially for JavaScript), and that you really need all that asset weight on each page.
Consider exploring Useful Rails javascript expansions for EXTJS to learn how to streamline JavaScript file inclusion in Rails using the EXT JS framework. You might also find Writing Compressible JavaScript helpful, as it provides strategies to optimize JavaScript code for better compression and performance.
If you're using Edge Rails (or > 2.1, which isn't out at time of writing), and are using the EXT
One of the things I really loved about Rails in the early days was that it introduced me to the conc
A lot has changed in the last few years when it comes to implementing applications using JavaScript.
I use Jasmine as my JavaScript unit/behavior testing framework of choice because it's elegant and ha