Simple JS and CSS compression for MonoRail

John | .Net, Web Standards, MonoRail | Wednesday, February 11th, 2009

Just came across a post about JavaScript compression for MonoRail. These guys have written a great patch for Hammett’s CombineJS Component.

I managed to apply the patch easily enough and now my default view code simply has the following brail code within it for generating minified JS. CSS files can also be added into the combine mix.

<% component CombineJS, {@key : 'JS' }: %>
      ${combine.Add("Content/js/jquery.js")}
      ${combine.Add("Content/js/jquery.validate.js")}
      ${combine.Add("Content/js/other.js")}
<% end %>

For other JS files I have in other view files I can either combine then into the default view JS files by using the same key value or add them in separately via a separate key.

JS validation rendering patch

As per the recommendation of Yahoo regarding putting scripts at the bottom I’m going to have look into if it is possible to patch the MonoRail html rendering to stop the JS validation code being put at the end of each form, and putting it just before the closing body tag.

From what I’ve quickly looked into, the JS validation code rendering is done in the FormHelper class as part of the call to the FormEndTag method. Not certain if it will be possible to store the rendering code for later usage in the output rendering or not.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress | Theme by Roy Tanck