This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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: 65105
89
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: 65105
89
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