How to enable javascript on a public website?

I am creating a public site and I use a lot of jQuery and jQueryUI. I noticed that most sites on the Internet using jQuery and jQueryUI do not have this code on their pages.

<script type="text/javascript">
  $(document).ready(function(){

    $("a").click(function(event){
      alert("Thanks for visiting!");
    });

    $( "input:submit" ).button();
  });
</script>

I know this is a simplified example, but most sites, like SO, contain only one obfuscated js file for all pages. It doesn't even look like they are using $ (document) .ready anywhere. On my current site, it seems that I will need to add a js file for each page. My question is how should this be done, and is there any best practice to use / enable javascript on the page?

+5
source share
3 answers

. , , . js , :

<script type="text/javascript" src="site.js"></script>

.

+4

If you add the file "site.js" at the top or bottom, it doesn't matter if your javascript does not do document.write to put something on the page. Then, of course, upstairs would be desirable. Some people like this at the bottom so that the rest of the page loads before loading the js file, which can sometimes delay page loading if it is a large file.

+1
source

All Articles