I am looking for better methods to use javascript/jQuery
snippets in an asp.net project. I know that it is best to put all the scripts in a separate file, and not in a line. It's good. Itโs easy to move these script functions to a common file (it may be slightly different to align the loading performance of one large file for small functions).
But there are some jQuery
things that should happen on document.Ready
on every page. How to transfer this to a shared .js
file? I would like to avoid one script per page, as that would be too much.
For example, say Page1 needs to be manipulated by several switches at boot time and has the following script built in. (for illustration only)
<script> $(document).ready(function() { </script>
Same with Page2, but for some other condition, calling a different function2 function2
.
I can move functions1 and function2 to a common .js
file, but what about document ready
sections. Should it stay in line? I think so, because otherwise Iโm not sure how common.js
will distinguish document.Ready
for different pages.
Then it robs the target of not having inline javascript
? If someone can shed light on this, he is very much appreciated.
I did some research, but probably due to the wrong keywords, so far I have not been able to find any good information in the same areas. Unobtrusive JavaScript seems promising in the comments below.
source share