• Post Reply Bookmark Topic Watch Topic
  • New Topic

Js embedded in Jsp file  RSS feed

 
wrushasen dakhane
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

To improve the performance of the application it has been suggested that we should remove the js content from each jsp file and create a new separate js file and then include that file in the Jsp.

By doing this I want to know whether this will have any performance enhancements.

Can you please suggest anything else to enhance the performance?

Best Regards,

Wrushasen
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be more appropriate solution instead of writing a same code in each file..
or can say "write once use anywhere" make sounds good.
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi wrushasen,

including js files from your jsp's is better than copy/pasting them into your jsp's, but if the performance gain will depend on the size of those javascripts, and on the speed of your connection.

(if you are on a fast intranet you probably won't notice any difference).

Other performance tips: often database related (check which queries are slow)

Herman
 
wrushasen dakhane
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"but if the performance gain will depend on the size of those javascripts, and on the speed of your connection."

I didn't understand this statement.

Can you through some light on js file is compiled by the browser ?

Are you sure that by seperaintg the js code in different file will increase the performance significantly?

Other than queries can you suggest any other area to look after or concentrate on.

Wrushasen D.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by wrushasen dakhane:
Are you sure that by seperaintg the js code in different file will increase the performance significantly?


Nobody here said that doing so will increase performance significantly.

If you have a large amount of javascript code, putting it in a separate file will allow your browser to cache it. This has the potential to reduce the amount of data returned from a request to your server. For people with slow connections (dial up) this could result in your pages loading a little faster.

As Saif suggested performance is not the best reason to structure your code this way. Separating your HTML and javascript (or any separate concerns) makes your code more manageable and easier to maintain in the long run.
That, to me, is the best reason for re-structuring.
 
wrushasen dakhane
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"This has the potential to reduce the amount of data returned from a request to your server"

Are you sure about this...Can you please eloborate on this?

Best Regards,

Wrushasen Dakhane.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66149
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by wrushasen dakhane:

Are you sure about this...Can you please eloborate on this?


If the browser caches the separate .js file it will not need to be fetched on each subsequent page load or on any other pages that reference that same .js file, thus reducing bandwidth usage.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by wrushasen dakhane:
Can you please eloborate on this?



Suppose you have 500 lines of Javascript and 100 lines of HTML in a page that is called repeatedly by the same user in your app.
That's 600 lines of text with each request to that page by that user.

Now, suppose you take the 500 lines of Javascript and move it to a separate file. The first time the user hits your page, s/he will download all 600 lines, the .js page will be cached. As long as the last-modified header doesn't change on that file the browser will keep using the cached version on the client's machine. This means that all subsequent hits by that user will only result in 100 lines of text being sent from the server to the client.

Make sense?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!