Skip to content

Comment on Best practices for JS and CSS organization

Comments

I used to organize js binding based on the controller (https://github.com/pivotal/jelly), but found that it is better to base it on the template.

There are a few reasons:

1. It makes more conceptual sense. The javascript relates to html (which is generated by the template), not a controller action.

2. You will probably want to reuse templates across different controllers. Also partial templates can have reusable behavior.

3. It is easier to move between the associated javascript + template

4. Refactoring is easier, especially with html gotten via AJAX

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.