marvelTracker
marvelTracker

Reputation: 4969

JQuery patterns and best practices in Asp.net MVC 3.0

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 ?

Upvotes: 4

Views: 1267

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039528

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.

Upvotes: 4

Related Questions