• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Including .js files into certain pages

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone suggest how I can put together some Javascript to check which page I am on and load the approriate js file into the header?

I am using an include file for my header but do not want all of my JS files loaded into the header, so thought I could write some loginc to only load the appropriate JS file(s) for that page.

I have the basic:-


To find my url, but what I want is something like:-



Cheers in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I just hand-tune what each page needs rather than use some complicated and possibly fragile mechanism. But, you might want to check out jQuery's $.getScript() function.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also look into the decorator pattern and/or just use an existing solution like SiteMesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic