Hacker News new | comments | show | ask | jobs | submit login

I like your suggestion of using RequireJS. I'll add that to the next revision of the article.

Your strategy of using two JS scripts per view, one site-wide and one page-specific is interesting. I wonder how to test the performance to really determine the value. Maybe look at time-to-render?

I do this as well. I break apps into "components" -- each component has it's own CSS and JavaScript file. A component covers a logical domain, such as administrative functions, or a reporting piece.

Then I have an application level CSS&JS that has everything generic in it. This is for a reasonably big app, so the overhead of having a single CSS/JS isn't insignificant - particularly when supporting mobile devices.

The other useful thing is a I as a dasherized version of the controller name and action to the body tag - as an id and a class respectively. So the body tag is something like <body id='my-controller' class='show'>

I also expose these as JavaScript globals CONTROLLER and ACTION (I also have LOCALE and COMPONENT).

These constructs are to be used sparingly -- you don't want to mash everything together too much -- but they're very handy when used right.

Yes I guess that would be the right metric. You'd need to look at average time to render over a number of deploys with both strategies. I'm pleased to see articles approaching this subject as there's definitely not enough solid discussion around this.

One other optimization you may want to talk about in your next article is to use a gem like the asset_sync gem to upload your assets to S3 or CloudFront (or similar) at compile time.

I'd like to look deeper into this option. I didn't mention it in the article, but @jo_liss suggested hosting all assets on CloudFront in production. She points out that you can set up CloudFront and get your own content-delivery network in five minutes. Once you have your own CDN, there's no advantage to using any 3rd-party JS host.

That's somewhat true. However, using Google does have an advantage over your own CDN -- it's more likely to already be cached in someone's browser.

On these occassions the hit to download JQuery (or something big like JQueryUI) is zero.

This is more a consideration for a landing page than a heavy-use application though.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact