• Post Reply Bookmark Topic Watch Topic
  • New Topic

.jsp vs .js

 
Vijay K Vivek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be a very trivial question. But please bear with me. I have tried googling on the same and cannot find any concrete answer. Hence posting here.

In my project we write all the javascript functions in a jsp and we will include this jsp where ever required. What is the difference between doing this way and writing the javascript as a .js and use the script functions fromthere?

When to write javascript functions in a jsp and when to put the same in .js file?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are differences, but in this case they are more trivial than important.

JSP files will always be compiled into servlets and executed each time the file is requested. JS files can usually be treated as static files and can be served more efficiently, but you are unlikely to notice the difference.

JSP files are sent as text/html content types by default, JS are not, although again you are unlikely to notice the difference.
 
Vijay K Vivek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply.
One more question as a follow up to the same. In JSP we use JSP comments in order to explain the code logic. Advantage is that it will not be served in the html of the response and will not be added to the payload.
But if we use a html comment it will add to the response html.

If I use a js file instead of jsp, I cannot give JSP comments because it is not a jsp file. Is there any type of comments I can use so that it will not appear in the served html?
[ October 17, 2007: Message edited by: Vijay K Vivek ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, the js file will be served 'as-is' while the JSP file is run on server.
 
Vijay K Vivek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!