• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conditionally load a java script file

 
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
Pie
Posts: 65124
91
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic