This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Conditionally load a java script file  RSS feed

 
PradeepPillai Pradeep
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a javascript file called "sitestat.js". We have it included in many jsp files that are reusable and we construct other main jsp files using these reusable jsps. The problem is that as a result of including these reusable jsps in other jsps, we ended up including "sitestat.js" multiple times in a jsp. Is there any way to load a jsp file conditionally only if it is not loaded already?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need better organization for your JSP files. But as I doubt you;'d take that advice, you can set a scoped variable in the request when you include the script file and check it later to see of you need to include the file again. The <c:set> and <c:if> JSTL tags can be used for this. In fact, you can even write a custom tag to handle all of that for you in one place.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!