I am working on an ASP.NET MVC application and using jQuery.
I understand from various web resources that I should:
- Reference the google CDN for loading jQuery library. (No problem with that)
- Combine, minify and compress my javascript files into one file.
- NOT write JavaScript code in view files.
Now the problem is that on different views, I need to do different things when DOM is ready. For example lets assume I want to slideUp element with id ID1 on View1 and slideDown element with id ID2 on View2. How can I do this from single js file?
As I see it, I don’t think your project / application is going to support that pattern of improving performance. Personally, if you have a lot of view-specific JavaScript going on (do X on View1, Y on View2), I think your view templates are the perfect place for them. I would: