// @reference not working for named bundles

352 views
Skip to first unread message

John Reilly

unread,
Feb 21, 2013, 5:01:46 AM2/21/13
to cass...@googlegroups.com
Hi Guys,

I'm having a problem with using the // @reference mechanism to manage my script dependencies.  

In an ASP.NET MVC 4 project I have a view specific javascript file called Edit.js.  The first line looks like this:

// @reference "~/bundles/validate"

This is in place to reference the following bundle set up in my CassetteConfiguration.cs:

            bundles.Add<ScriptBundle>("~/bundles/validate",
                                      new[]
                                          {
                                              "~/Scripts/jquery.validate.js",
                                              "~/Scripts/jquery.validate.unobtrusive.js"
                                          },
                                      bundle => bundle.PageLocation = "dependsOnCore"
                );

The bundles are rendered out in 3 statements in my layout.cshtml which look like this: (2 page locations and 1 standard)

    @Bundles.RenderScripts("core")
    @Bundles.RenderScripts("dependsOnCore")
    @Bundles.RenderScripts()

However, the "~/bundles/validate" bundle does not get automatically pulled in as I would expect.  It just gets ignored.  I'm working round this by having the following 2 statements in the head of my Edit.cshtml 

    Bundles.Reference("~/bundles/validate"); // Make sure this bundle is referenced as cannot rely on this: @reference "~/bundles/validate"
    Bundles.Reference("~/Scripts/Areas/MyArea/Views/MyEntity/Edit.js");

Am I doing something wrong?

Andrew Davey

unread,
Feb 21, 2013, 5:16:23 AM2/21/13
to Cassette
If you go to /cassette.axd, does it show your page bundle referencing ~/bundles/validate?




--
You received this message because you are subscribed to the Google Groups "Cassette" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cassette+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Reilly

unread,
Feb 21, 2013, 6:29:44 AM2/21/13
to cass...@googlegroups.com
Hi Andrew, it doesn't no.

John Reilly

unread,
Feb 21, 2013, 6:32:02 AM2/21/13
to cass...@googlegroups.com
It looks like this:

<script src="/cassette.axd/asset/Scripts/jquery-1.9.0.js?587fCfdOEB-QxHVlug5eQS4u3BI=" type="text/javascript"></script>
<script src="/cassette.axd/asset/Scripts/jquery-ui-1.10.0.js?1Q_APZlctdzVRqlplrQDa8N866o=" type="text/javascript"></script>
<script src="/cassette.axd/asset/Scripts/jquery-ui.autocomplete.custom.js?qyF6_80s4P8CuNfEUjOLS2W_E0Q=" type="text/javascript"></script>
<script src="/cassette.axd/asset/Scripts/amplify.js?HJmm3unTNK2aOzMdol2JpXhODH8=" type="text/javascript"></script>
<script src="/cassette.axd/asset/Scripts/site.js?XQgDJpX98UiggckHUoV3CF507XM=" type="text/javascript"></script>

    
<script src="/cassette.axd/asset/Scripts/Extensions/jquery-ui.datepicker.pubSub.js?H4EZxLiqDj2pRvwjZmi7_kqHPOI=" type="text/javascript"></script>
<script src="/cassette.axd/asset/Scripts/Extensions/jquery-ui.autocomplete.countryState.js?cUVAQ081juiFCyex3TNg8ppTcxI=" type="text/javascript"></script>
<script src="/cassette.axd/asset/Scripts/Extensions/jquery-ui.autocomplete.gicsCode.js?m__xotl9Yv7FLniErkhwvX-u30o=" type="text/javascript"></script>

    
<script src="/cassette.axd/asset/Scripts/Areas/MyArea/Views/MyEntity/Edit.js?jKGyVGcZ2z17f4Ttw-5C3X6ql1M=" type="text/javascript"></script>

John Reilly

unread,
Feb 21, 2013, 6:33:53 AM2/21/13
to cass...@googlegroups.com
Sorry - I realise what you mean now.  And no - it just lists this:

Andrew Davey

unread,
Feb 21, 2013, 9:43:16 AM2/21/13
to Cassette
Actually, it's my fault the references aren't shown. The diagnostics handler isn't checking for asset-level references! Let's ignore that problem for now.

Do you have Cassette's HTML rewriting switched off? In web.config, check the <cassette /> section.

John Reilly

unread,
Feb 22, 2013, 4:48:34 AM2/22/13
to cass...@googlegroups.com
Hi Andrew,

I don't have Cassette's HTML rewriting switched off - my configs don't make use of the <cassette /> section...

John

Andrew Davey

unread,
Feb 22, 2013, 12:05:23 PM2/22/13
to Cassette
I've run out of obvious reasons this could be breaking. Are you able to create a minimal project that reproduces this problem and email it to me - and...@equin.co.uk - please? I can then try to track down what's going wrong.

Thanks.

John Reilly

unread,
Feb 26, 2013, 4:06:08 AM2/26/13
to cass...@googlegroups.com
Sorry about the delayed reply Andrew - yes I'll try and put that together for you and mail it over.

John

John Reilly

unread,
Feb 26, 2013, 4:58:18 AM2/26/13
to cass...@googlegroups.com
Sent it now.

John Reilly

unread,
Feb 28, 2013, 4:00:20 AM2/28/13
to cass...@googlegroups.com

John Welborn

unread,
Jul 19, 2013, 4:39:16 PM7/19/13
to cass...@googlegroups.com
Did you guys figure this out?  I'm having essentially the same problem.  For some scripts it seems to be ignoring /// <reference style as well as @reference.

I've tried Adding Bundle.txt and it shows that it references the ~/Scripts/jquery bundle AND I'm including the jquery bundle on the page before the view specific script and yet I'm still getting errors about jquery not being defined.

x - fingers crossed.

Manfred Lange

unread,
Dec 30, 2013, 9:28:29 PM12/30/13
to cass...@googlegroups.com
I've got a similar problem but don't know whether it is related or not.

I have two files let's call them a.js and b.js. The file b.js references file a.js as follows:

// @reference a.js

Now, if I configure the bundles using bundles.AddPerIndividualFile(), this works and a.js is rendered before b.js. This is the expected behavior.

However, if I configure a single bundle using bundles.Add(), then this doesn't work and b.js is rendered before a.js. Since there is a dependency the code in b.js now fails since a.js is not yet available when it is executed. In this scenario I can fix this problem by using the file bundle.txt.

I looks to me like a duplication if I have to use bundle.txt in one case while using // @reference works well in the other case.

Background: I want to bundle differently during debugging/testing on one hand and for production/release on the other hand.

Perhaps I am overlooking something. I'd appreciate any points that would help figuring out why the @reference is ignored in the scenario with just a single bundle.

Matthew Abbott

unread,
May 28, 2015, 10:58:41 AM5/28/15
to cass...@googlegroups.com
Did you have any luck with this. I've just performed an upgrade to Cassette 2.4.2 from a rather older version, and now @reference is just not working for named bundles.
Reply all
Reply to author
Forward
0 new messages