I'm running a fairly large web application which contains an increasing amount of JQuery code for both UI polish and making AJAX requests.
Larger chunks of code live in their own, dedicated .js
file, but there are an increasing number of pages (primarily forms) which use a small sprinkling of JQuery for showing/hiding form elements, modifying classes etc. Presently I put this code in the $(document).ready()
block in my main application.js
file.
Given this, on any given page view application.js
is loaded and all the JQuery code in this ready()
block is executed despite the fact that only one or two calls will be relevant to the current page. Are there any performance implications of doing this or is it actually quite negligible? If there are performance implications, what is the recommended alternative way of managing these page-specific JQuery (or indeed any type of Javascript) snippets in large Rails apps?
Despite being considered bad-practice, wouldn't it make more sense to define simply JQuery rules which are specific only to a single form inside the form partial itself?