Question about paths of included JS libraries for a production machine

LabKey Support Forum (Inactive)
Question about paths of included JS libraries for a production machine Leo Dashevskiy  2013-08-09 18:29
Status: Closed
 
Hello, folks!

In one custom module I have the following path for custom JS libraries <module_name_1>/resources/web/OpenCyto:

In a different module I need to include a library from that first module, moreover I must include it not through the begin.view.xml file way, but directly in my <module_name_2>/resources/view/begin.html file within a <script> tag (it does not work through the begin.view.xml file way, may be, because it needs jQuery, which I also must include via a <script> tag before the call below):

<script type='text/javascript' src='../../OpenCyto/FancyBox/source/jquery.fancybox.pack.js'></script>

This works fine on 2 development machine, but fails on the production machine with the following error:

"Failed to load resource: the server responded with a status of 404 (Not Found)"

I am thinking this is because I 'hacked' its path on a dev machine via: '../../OpenCyto...' and the folder structure is different on a production machine.

So, please, help me make it generic, so that it works on both production and development machines or otherwise advise what to do!

Thanks.
-Leo
 
 
jeckels responded:  2013-08-14 10:51
Hi Leo,

In general, we recommend that developers include references to required JavaScript files via the .view.xml file. If you haven't already tried it, you can likely include a reference to jQuery there as well, which might solve your problem.

If that doesn't work, though, you may be able to use the special <%=contextPath%> substitution in your .html file:

https://www.labkey.org/wiki/home/Documentation/page.view?name=addHTMLandWebPart

I don't know what your exact file layout looks like, but it would likely be something like:

<script type='text/javascript' src='<%=contextPath%>/OpenCyto/FancyBox/source/jquery.fancybox.pack.js'></script>

That should work regardless of what LabKey folder/project it's being used in.

Thanks,
Josh
 
Leo Dashevskiy responded:  2013-08-14 11:58
Exactly, Josh!

contextPath is what I was after - Kevin already gave it away recently and I forgot to close the issue.

Not to drag jQuery around (I mean, to reduce the package size) and in order to get the latest version of jQuery, I use a CDN distributed copy via the <script> tag, hence my difficulties...

Now if the .view.xml file could take a web reference to jQuery that would be awesome, but I don't believe, that's the case, I think, I tried that already...