Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best practices to add jquery to asp.net?

Tags:

jquery

asp.net

I apologize if this question has been asked, but I can't find a question for this anywhere.

I would like to use jquery on my asp.net page, but should I just register a new script? Add a link? Is there some special reference I can add?

scottgu states that it's integrated into visual studio, but doesn't describe how to get started adding it to a page?

like image 781
McKay Avatar asked Jan 27 '26 11:01

McKay


2 Answers

I can not call them best practice, but some notes:

Add a link is the first think that you can do, if you register it as new script you add extra code to run with out reason.

Where on page: jQuery is a core library so load it on top of the page vs the bottom of the page that we left other javascript function to load and use them after the dom ready.

What version to add and from where ? You can add the minified version of jQuery, and you can ether load it from your site, ether load it from google. This is also depend if you keep only the jQuery or add it together with other script to a common file.

What to look for: In case that you have any conflict with other libraries you can use the jQuery noConflict http://api.jquery.com/jQuery.noConflict/

Optimize all your script: If you have more than one script to load, one optimization is to place them all together to a singe file, minified, gzip it, and add it as link to your pages. This is what I do after I follow and all the previous steps.

like image 86
Aristos Avatar answered Jan 29 '26 01:01

Aristos


You can add jQuery to asp.net by linking the scripts, just link these like you do your other scripts and stylesheets. [unless I missed something]

like image 37
Mark Redman Avatar answered Jan 29 '26 00:01

Mark Redman