This article was written in 2015, before Webpacker and React became mainstream. Much of this article refers to practices aimed towards Rails 4's asset pipeline.
Some sites don't need big JavaScript architectures, only bits of small behaviors that will affect certain elements. I prefer to put them into a directory called behaviors
.
class
(or role
) it affects.Just include them all into one file. In Rails, this should be as easy as:
This JavaScript will be safe to include in all pages.