It’s been quite some time since I’ve done front-end development and I’m having some issues… My current file is at this location on my server:
/home/www/mysite/sites/all/custom_includes/roster/user_roster.php
I have a js file located at:
/home/www/lib/jquery/jquery.fancybox.js
If it was a php file I was trying to include, I could do something like this:
$jsPath = '/home/www/lib/jquery';
require_once($jsPath.'/jquery.fancybox.js');
But it doesn’t seem to work with a script tag. I tried it like this:
<script type="text/javascript" src="<?= $jsPath; ?>/jquery.fancybox.js"></script>
but it evaluates to
<script type="text/javascript" src="/home/www/lib/jquery/jquery.fancybox-1.3.4.pack.js"></script>
which gives me a page not found error. Am I stuck using 10,000 levels of ../ in my script src path to get the file? Or is there a better way?
You need to think about it from the client’s point of view when dealing with js.
Your path should be:
/lib/jquery/jquery.fancybox-1.3.4.pack.js
The client’s paths are relative to your web server root, in this case being /home/www
Also remember that you cannot access files at a higher level than /home/www from the client without going through a server-side script.