javascript - Using Minified Page Specific JS -


I am working on a very large scale project which uses many different pages with some very specific javascript Does each one of them To reduce load time, I plan to compress it all in a file before deploying it.

The problem is: How should I avoid launching page specific JS on those pages which are not required? So far my best solution is to wrap each page in some extra containers

    

And I have expanded jQuery so I can do something like this:

  // If this element exists then when the DOM is ready, the function Execute $ ('#some_page') ready (function () {...});   

Which, while cool, like just rubs me wrongly?

I get every page in the & lt; Body & gt; element:

  & lt; Html & gt; & Lt; Head & gt; On completion of giving a unique ID .. & Lt; / Head & gt; Body id = "sign-in" & gt; ... & lt; / Body & gt; & Lt; / Html & gt;   

And write all my page-specific scripts in jQuery blocks like:

  $ (function () {if (! $ ('Body # Sign-in '}.);    

Comments