ChumpStick
ChumpStick

Reputation: 51

Bundled scripts, render but don't work after publish in vs 2017

I have a webiste that I was building in vs 2015 and some stuff happened when I tried to regrab the project from source control and long story short I couldn't get it to publish in vs 2015, because of a MSBuildTools error I couldn't fix.

I was able to get the site to publish in vs 2017 and now the javascripts all render on the site, but none of them work. I have no idea what is going on. It's the exact same project as it was when I was working on it in vs 2015 where the javascripts all rendered and worked fine when I was able to publish it.

When I debug in either vs 2015 or 2017 the javascripts all render and work perfectly.

Here is a snippet of my BundleConfig.cs...

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/Bundles/Scripts/Areas/Admin/AdminBar").Include(
            "~/Scripts/Areas/Admin/AdminBar.js"));

    BundleTable.EnableOptimizations = true;
}

The EnableOptimizations I comment out when I and debugging locally.

Also all the bundled css render and works fine when I publish it.

Oh and I use what I believe they call modularized scripts? Where my .js files look like this...

Scripts.Areas.Admin.AdminBar = (function (my, $)
{
    // Local variables
    my._settings = {};

    my.setup = function (settings)
    {
        my._settings = settings;
    }

    return my;
}(Scripts.Areas.Admin.AdminBar || {}, jQuery));

And then in my view I render it like...

 @Scripts.Render("~/Bundles/Scripts/Areas/Admin/AdminBar")

Then in the view would call a function from that file like so...

<script type="text/javascript">
    Scripts.Areas.Admin.Adminbar.setup()
</script>

Upvotes: 0

Views: 429

Answers (2)

Diablo
Diablo

Reputation: 169

When you say "...now the javascripts all render on the site, but none of them work", what do you exactly mean? Do you see any javascript errors on browser console? If you don't see any errors did you try adding something like an "alert('This is a test');" to your js file and see if it hits?

Also, If you are absolutely sure that scripts were rendered, to narrow down the issue, try the un-optimized version of js and see if it works. If it does, then there's clearly something missing/ erroneous in the optimization process which we may need a different approach to look in to. If it still does not work, put the 'debugger' statement to any of the javascript functions being called and see if you could get any of the methods to break in within the browser's console. Keep browser console open while you do this.

Upvotes: 1

ChumpStick
ChumpStick

Reputation: 51

Ok call off the dogs! I figured it out. Actually with the help of Diablo's comment. I saw in the browser that it was saying that the was an error loading Jquery. So I looked at my project and since NuGet had re-installed all my packages that jquery scripts were there but not included in my project. Which explains why it worked when debugging locally, but not when I would publish it. It was leaving those jquery scripts out of the publish.

So Thanks Diablo... would give you credit for this, but you only posted a comment and I don't know how to mark your comment as helpful.

Upvotes: 0

Related Questions