This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

best practice in developing a web-application  RSS feed

 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it the best practice of placing all the scripts use in different pages to be placed in the header file??

I think no because if a page do not uses a particular script and it is still loading and wasting processing time and memory..
what is the correct way..
please correct me..
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "scripts" you mean JavaScript files?
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about it.


It's kind of the same thing as asking "What is the best way to fetch data from a database? Lazy or eager?" or "Which is the best web framework for all my applications?"


Also, why would you put a script you don't use in a page?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, javascript files, jquery files ..
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ways are :

1. one way is that i put each and every script (javascript, jquery) in <head> of header file and import them using <jsp:include>

2. other way is not to use <jsp:include> and use the script file in <head> of each page .
i.e don't use <jsp:include>

which is the best?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither. You don't want to use jsp:include at all. Why would you do that?

And you should only include script that's going to be used on the page.

Let me guess, you're using Tiles or some other templating system and want to know how to choose only scripts that need to be included on each page?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i am using bootstrap..
yes Bear Bibeault, you caught my feelings.. :)
and thanks Bear Bibeault, i think,i got my answer,,

what i done till now :
i create one header file , and import all the jqueries, javascripts in that page, and use <jsp:include> on each page because every page needs header, and with that header all the javascripts, jquery are also included in each page

and its a wrong way?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure exactly how you are using includes.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my header.jsp




index.jsp :





footer.jsp


I am coding like this..
please correct me for my mistakes..

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with that, of course, is that by including the same header in every page, you are including a bunch of stuff that's not needed.

I'd include only scripts in the included header that are used on all pages, and include other scripts on each page only as needed.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok .. thanks Bear Bibeault .. :)
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, is it a good approach to use <script> within <body>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is prevailing wisdom that putting the script tags at the end of the body improves loading performance.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!