|
When you're creating jQuery script for elements on a page (be that plain HTML, CF, ASP.NET, PHP or other) do you write the JavaScript into the page, or do you write separate JS files and use a link to import them? It seems to me that the code often belongs with the elements that are defined in the HTML, and so belong in the HTML file, but I can imagine that there are systems out there that could minify JS files on the fly and reduce bandwidth requirements. Samples don't help guide us to the best practice because they are trying to show the simplest way of doing things so that we can focus on the code in the example, not the implementation. Is there a best practice regarding where we put the JavaScript code? |
|
I think it really can depend on the situation. I like to keep my jQuery scripts on the same page as well, but in some case there may be a need to use a separate file to keep things organized when your page is becoming complex (maybe because it uses a lot of javascript/jQuery or you end up in affect creating your own jQuery plugin that you may want to reuse somewhere else). |


