tags:

views:

95

answers:

1

Hi Folks,

what is the best practice to include Javascript to your webapplications ?

Think about the following situations :

Different HTML Pages NO JavaScript Framework like JQuery or Dojo Different JS-Functions for different Pages.

Iam not sure, but i think there are 3 Solutions ?

  • Include the stuff directly in the html file
  • Put the stuff in one big .JS file and use some kind of namespace(s)
  • Use on .JS File for every html page, with the needed functions included ?

Iam looking forward for your suggestions.

+3  A: 

Depends entirely on your visitors behavior.

If you anticipate/get a very low repeat visitor rate over the course of a month, or you have an average number of page views per-visitor between 1-2, you should place all JS and CSS directly on the page to cut down on HTTP requests.

However if most of your visitors are looking at 2+ pages that use the same resources, you'll want to put everything in external js/css files.

Whether you separate your resources into multiple files will depend on how often visitors land on pages using the same resources. For instance, you might want to place the CSS/JS for a contact us or similar not-so-often visited page in its' own files.

joebert
that makes it clear, thanks a lot
ArneRie