locked
Confusion over referencing <link> javascript files RRS feed

  • Question

  • CRM 2013 On-Premise

    I have a HTML web resource and rather than put the javascript inline I thought I'd put it in a separate library and reference it....only I'm doing something wrong because the console is throwing a 404 not found when loading the script.

    In the solution my resource shows this path (sterilized):

    http://dynamics/MyOrg/WebResources/xxxx_jscriptFunctions

    Now according to the sdk, online and looking at other developers working html resources it seems that this should work:

    <script type="text/javascript" src="../scripts/jscriptFunctions.js"></script>

    Grasping I've also tried:

    <script type="text/javascript" src="../../xxxx_/scripts/jscriptFunctions.js"></script>

    What am I doing wrong?

    Friday, April 18, 2014 6:11 PM

Answers

  • It depends on the new you gave the file when you created it.

    You can create a pseudo folder structure by naming you web resource like: prefix (fixed) + "/scripts/jscriptFunctions.js".  So if you enter a "path" in the name it will follow the same type of rules when referencing via an absolute or relative value in the HTML page. So "scripts/jscriptFunctions.js" should work for the script source. Here you don't worry so much about the prefix of the web resource because the full pseudo path would be something like "prefix_/scripts/jscriptFunctions.js".

    If you didn't use that approach and just named the file like: prefix (fixed) + "jscriptFunctions.js" you would reference "prefix_jscriptFunctions.js". Here you need to include the prefix. You shouldn't need to include anything in the path before the file because both the HTML page and JavaScript page should both be at the same tree level under the "webresources" folder.


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, April 18, 2014 7:40 PM
    Moderator
  • So humor me please...using this example:

    named xxxx_ + /images/myimage.png

    http://dynamics/MyOrg/WebResources/xxxx_/images/myimage

    What should me src="" be?

    if the webresource name is xxxx_/images/myimage.png and the full path (as showed in the url bottom field) is http://dynamics/MyOrg/WebResources/xxxx_/images/myimage.png (again, if the name doesn't contain the extension also the full path will not contain it and viceversa)

    the src file for a webresource stored in the root path (for example xxxx_index.htm) is

    src="images/myimage.png"

    if the webresource is stored in the same path (for example xxxx_/images/index.htm) the src is

    src="myimage.png"


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by zzpluralza Tuesday, April 22, 2014 9:56 PM
    Friday, April 18, 2014 11:30 PM

All replies

  • It depends on the new you gave the file when you created it.

    You can create a pseudo folder structure by naming you web resource like: prefix (fixed) + "/scripts/jscriptFunctions.js".  So if you enter a "path" in the name it will follow the same type of rules when referencing via an absolute or relative value in the HTML page. So "scripts/jscriptFunctions.js" should work for the script source. Here you don't worry so much about the prefix of the web resource because the full pseudo path would be something like "prefix_/scripts/jscriptFunctions.js".

    If you didn't use that approach and just named the file like: prefix (fixed) + "jscriptFunctions.js" you would reference "prefix_jscriptFunctions.js". Here you need to include the prefix. You shouldn't need to include anything in the path before the file because both the HTML page and JavaScript page should both be at the same tree level under the "webresources" folder.


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Friday, April 18, 2014 7:40 PM
    Moderator
  • Jason this is what's confusing me. I have read and re-read this section in the sdk and my pea brain isn't getting it.

    ...a relative URL can be used. To enable this, we recommend that you use a consistent naming convention for the web resources that reflect a virtual file structure. The solution publisher’s customization prefix will always be included as a prefix to the name of the web resource. This can represent a virtual ”root” folder for all web resources added by that publisher. You can then use the forward slash character (/) to simulate a folder structure that will be honored by the web server.

    Here is how I add my resource:



    • Edited by zzpluralza Friday, April 18, 2014 8:05 PM
    Friday, April 18, 2014 8:03 PM
  • I don't get it...but I seem to be the only one???  I just created a new resource as such:

    named xxxx_ + /images/myimage.png

    and it seems to have parsed into the virtual directories as you say

    http://dynamics/MyOrg/WebResources/xxxx_/images/myimage

    using this in the html web resource and the file STILL is not found!!!?????

    src="../images/myimage.png"

    or

    src="images/myimage.png"

    Now looking at the console I see:

    http://localhost/MyOrg/%7B6....%7D/images/myimage.png

    for the first src and below for the second.

    http://localhost/MyOrg/%7B6....%7D/WebResources/images/myimage.png

    as you can see it is traversing up and down as the first is missing the WebResources folder.


    • Edited by zzpluralza Friday, April 18, 2014 9:15 PM
    Friday, April 18, 2014 8:48 PM
  • You confuse the local name of your file with the virtual name after the upload.

    To reference a js library (or a png picture or other webresources) you need to consider always the path written inside the "Name" textbox.

    You can upload a file called abclogo.png, but if inside the "Name" textbox the name is "prefix_abclogo" (without the extension) the full path of the file become

    http://dynamics/MyOrg/WebResources/prefix_abclogo (as written inside the uri field in the bottom) and not http://dynamics/MyOrg/WebResources/prefix_abclogo.png, it will not add the extension.

    the same with the javascript libraries, if the name field is prefix_testfunctions, the url IS NOT http://dynamics/MyOrg/WebResources/prefix_testfunctions.js

    the relative path depends the current level of the file that is including the library (as a normal website)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, April 18, 2014 10:43 PM
  • So humor me please...using this example:

    named xxxx_ + /images/myimage.png

    http://dynamics/MyOrg/WebResources/xxxx_/images/myimage

    What should me src="" be?

    Friday, April 18, 2014 11:14 PM
  • So humor me please...using this example:

    named xxxx_ + /images/myimage.png

    http://dynamics/MyOrg/WebResources/xxxx_/images/myimage

    What should me src="" be?

    if the webresource name is xxxx_/images/myimage.png and the full path (as showed in the url bottom field) is http://dynamics/MyOrg/WebResources/xxxx_/images/myimage.png (again, if the name doesn't contain the extension also the full path will not contain it and viceversa)

    the src file for a webresource stored in the root path (for example xxxx_index.htm) is

    src="images/myimage.png"

    if the webresource is stored in the same path (for example xxxx_/images/index.htm) the src is

    src="myimage.png"


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by zzpluralza Tuesday, April 22, 2014 9:56 PM
    Friday, April 18, 2014 11:30 PM
  • THANK YOU for your patience and persistence in helping me. I have figured out what I was missing...pretty obvious really. I understood the path to my image resources but my html resource that was consuming them was at the root so ../images etc. always failed because you can't go up one level when you are at the root....i.e. the fix was to make my html web resources follow a similar pattern to avoid confusion.

    xxxx_+/html/mywebpage.html

    Tuesday, April 22, 2014 10:01 PM