Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Henrik Sunesen 84 posts 281 karma points
    Nov 12, 2016 @ 22:39
    Henrik Sunesen
    0

    Client dependency loading order

    Hello all,

    I have a problem with some bootstrap js, I found the cause of the problem, right now I am loading the js files like this:

    Html.RequiresJs("/Scripts/jquery.min.js", 0);
    Html.RequiresJs("/Scripts/bootstrap.min.js", 0);
    
    
    @Html.RenderJsHere() <--This is right before </body>
    

    And that is not working, but if i take the bootstrap.min.js and make it like a normal html script like this:

     <script src="/scripts/bootstrap.min.js"></script>
    

    Then it works, so my question is.... why?

    Of my understanding the 0 in the Html.RequireJs means that it should load this file first, or am I totally wrong?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Nov 13, 2016 @ 11:17
    Marc Goodson
    100

    Hi Henrik

    without the ,0 in the RequiresJS method, the client dependency framework will load the scripts in the order they appear on the page, minimise the scripts in each file, and make them available in a single request.

    the ,0 controls their order so my first thought is to use:

    Html.RequiresJs("/Scripts/jquery.min.js", 0);
    Html.RequiresJs("/Scripts/bootstrap.min.js", 1);
    

    this would mean that Jquery would definately be presented before bootstrap.

    So what could be going wrong ?

    Everything could be fine, but the problem cached - make sure you increase the version number of the Client Dependency Framework in /config/clientdependencyframework.config

    also if you are working locally and have compilation debug set to true in your web.config, then the client dependency framework does not perform the minimising. So if it works in these circumstances but not in a production environment (eg where compilation debug is set to false) the the problem may lie in the minimising process (I've had odd spaces and characters causing issues in the past) - the way to troubleshoot this is to visit the generated dependencyhandler.axd?s=asdfsadfsa url directly in your browser and determine whether all of your content is there, usually the point at which it stops, is the point where the problem is.

    When viewing the minimised file directly in the browser, I often add &v=2 on the end, so I can be sure I'm not viewing a version cached by the browser.

    regards

    Marc

  • Henrik Sunesen 84 posts 281 karma points
    Nov 13, 2016 @ 18:17
    Henrik Sunesen
    0

    Hi Marc,

    Thanks for your advise,

    I tried to use the solutions you gave me, but with no luck :(

    Now it's ordered like you said:

    Html.RequiresJs("/Scripts/jquery.min.js", 0);
    Html.RequiresJs("/Scripts/bootstrap.min.js", 1);
    

    And I increased my ClientDependency version by 1.

    I am working "locally" on my server, with IIS, I tried to change the debug="false", but it still doesn't work for me.

    I don't get the "dependencyhandler.axd?s=" thing, what should be in the query after "?s=" ?

  • Henrik Sunesen 84 posts 281 karma points
    Nov 17, 2016 @ 13:39
    Henrik Sunesen
    1

    I found the problem.

    I had a @Html.RenderJsHere() at the button of the body, i removed that and that solved the problem.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Nov 18, 2016 @ 12:25
    Marc Goodson
    0

    Hi Henrik

    So it was rendering out your Javascript twice!!

    great you got it working!

    cheers

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft