1

I am currently working with web optimization bundler that is part of the .net framework that bundles up both my javascript and css in to a single file. This works nicely.

I have run in to a problem with it though. See the following code:

 BundleTable.Bundles.Add(new ScriptBundle("mybundle").Include( 
                "~/Scripts/globalize.js", 
                "~/Scripts/jquery.validate.js", 
                string.Format("~/resources.axd")));

This bundles up all the javascript from the files but also I would like to bundle the output from my .axd http handler. This returns javascript. However the javascript never gets included in the bundle. If I run the handler in my browser, no issue, javascript is returned.

I am wondering maybe the bundler does not recognize the .axd extension and therefore does not attempt to request the file. Any ideas if this is the case and the work around?

amateur
  • 43,371
  • 65
  • 192
  • 320
  • The default bundler appears to treat names beginningg with "~/" as Files and attempts to read them from disk. – Joe Feb 11 '13 at 19:20
  • Ok. What's the workaround? – amateur Feb 11 '13 at 19:23
  • 1
    http://stackoverflow.com/questions/1433512/asp-net-web-application-webresource-axd-and-scriptresource-axd-files-loading – Joe Feb 11 '13 at 20:15
  • http://www.codeproject.com/Articles/25929/Fast-ASP-NET-Web-page-loading-by-downloading-multi – Joe Feb 11 '13 at 20:17

2 Answers2

0

Correct, you can only include files into bundles, it will not make requests to the axd for you. What you can do is manually hit the axd, and save the file to disk and include that into your bundle.

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
  • Is it possible to load a file and add content the bundle directly when the bundle is being created? – amateur Feb 15 '13 at 08:44
  • Sure you could do it during PreAppStart when you are setting up your bundles – Hao Kung Feb 15 '13 at 19:10
  • cool - and how can you add content directly to the bundler? Any examples? – amateur Feb 15 '13 at 22:47
  • Why can't you just include the file in the bundle? You can't load content directly into the bundle currently, I misunderstood your question I think. – Hao Kung Feb 16 '13 at 00:37
  • The content is coming from a resource file which I am populating in a javascript variable that I want use on the client side. So I want to populate the content of the resx resource file in to this bundle, which is culture specific. – amateur Feb 16 '13 at 00:48
  • @HaoKung thanks for being on SO and answering questions about this, its good to have the actual developer on hand, its the best place to get real answers from :) Is there any plans to support .axd bundling/minimizing? eg behind the scenes it works by reading the .axd to a memory stream and adding it to the bundle. – JK. Aug 18 '13 at 22:19
0

I just wrote a script bundle for resx - you can find the source here

https://github.com/MrAntix/sandbox-resx-script-bundling

In BundleConfig, add your bundle ...

bundles.Add(
  new ResxScriptBundle("~/bundles/local")
      .Include<JsResources>("app")
  );

It creates a model for each resource like this ...

window.resources=window.resources||{};
window.resources.app = {
  "HelloWorld": "Hello World, from JSResources.resx"
};

And you can use it in your JS like this ...

$("h1").append(window.resources.app.HelloWorld);

... for example

Anthony Johnston
  • 9,405
  • 4
  • 46
  • 57