Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript src path

 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following is better way to specify the "src" path for javascript





 
Amit Goda
Ranch Hand
Posts: 37
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<script type="text/javascript" src="xxx.js"></script>

<!-- assuming "xxx.js" is at the same directory level of the including file so it can be located. -->


In above manner, you are specifying relative path and second one is absolute path. Both the ways are preferrable but i'll suggest to use relative path as it is more readable and short.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither.

If this is a web application it should be a server-relative URL starting with the context path of the web application.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, in the second option what I meant was



If I use what you suggested



It worked too. So do you think the following is ok ?



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the reference are to resource within the web app then no, I do not. It makes it impossible to move to another server without having to change all the links. References within the same web app should never use absolute URLs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic