This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes javascript src path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript src path" Watch "javascript src path" New topic
Author

javascript src path

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
Which of the following is better way to specify the "src" path for javascript





Amit Goda
Ranch Hand

Joined: Jan 21, 2012
Posts: 37

<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.


AMiT
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

Neither.

If this is a web application it should be a server-relative URL starting with the context path of the web application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
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

Joined: Jan 10, 2002
Posts: 60765
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript src path
 
Similar Threads
calling .js in jsp
Sessions on a servlet
Problem validating form with jQuery validation plugin
Ajax+ToolTips
external javascript