Wow. Rails compresses all my javascript files into one big file. Oh, that’s nice in terms of performance. But honestly I have a major problem. Considering that ALL my js files are loaded all at once — uhm — numerous variable clashes, code clashes, and other unexpected javascript behavior that are really frustrating started to appear almost in every page.
I end up having a bunch of if-else statements to make sure that the only the correct code will execute depending on the current context or current page. I also tried to manipulate the HTML by adding classes and id on the body to keep track in which controller-action pair does the page came from. I tried different techniques, but I find almost all of them complex and dirty.
If only there’s a simple way to organize my javascript files. If only there’s a way to execute a page-specific javascript.
Then I realized, “I can create a gem for that!”
read more

Home