4

I'm working with an Asp.net MVC 3.0 application and use JQuery + JSON . I'm planing to use jquery post and get methods to send/back data to server.As a result, my JQuery Code base will be large and should be maintainable.

so that what are the best practices and design patterns when using JQuery with ASP.net MVC 3.0 ?

1 Answer 1

4

Here are a few tips:

  • Always try to place javascript in separate js files and avoid placing it in views.
  • Never hardcode urls in your javascript files. Always use Url helpers when generating urls.
  • For javascript code that could be reused in multiple places, prefer to write a jQuery plugin.
  • Before writing some code, search whether someone hasn't yet written a jQuery plugin for it.
  • Minify your javascript files when running in release mode
  • Try to reduce the number of AJAX requests: for example prefer one AJAX request which sends/receives bigger data compared to multiple AJAX requests with smaller data.
Sign up to request clarification or add additional context in comments.

1 Comment

in addition you should make a single js file. Here are some other good advices, blog.stevensanderson.com/2011/07/22/… hanselman.com/blog/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.