Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:59:26+00:00 2026-06-17T14:59:26+00:00

I was experimenting with Bundle and Minification in MVC4 and came across an interesting

  • 0

I was experimenting with Bundle and Minification in MVC4 and came across an interesting problem.
I am using Coffeescript and I would like a Render helper that works a bit like the @Scripts.Render() method.

For example, let’s say I have this bundle config:

new ScriptBundle("~/bundle/appfiles").Include(
    "~/Scripts/app/sample.js",
    "~/Scripts/app/myApp.js");

In the cshtml, when I do @Scripts.Render() I get different results based on the debug setting in the web.config. If debug is true I get one script tag per file, otherwise I get a single script tag that returns the bundled and minified js. This is fine.

Let-s assume now that I want to do the same with my Coffeescripts. I create a bundle like this:

new Bundle("~/bundle/appfiles", new CoffeeBundler(), new JsMinify()).Include(
    "~/Scripts/app/sample.coffee",
    "~/Scripts/app/myApp.coffee");

The problem now is that if I use @Scripts.Render() I get, while in debug, one script per file but this is not transformed at all. The only use I could do is this:

<script type="text/javascript" src="@(BundleTable.Bundles.ResolveBundleUrl("~/bundle/appfiles"))"></script>

But this will, even in debug mode, bundle everything together and then minify, which of course is not what I want.

I have tried to create a Coffee.Render() helper similar to the Scripts one but it uses the AssetManager class which is internal to the System.Web.Optimization assembly.

I was wondering if you have an idea on how to do this in a clean way (i.e: using the available public classes, not copying and pasting the whole AssetManager code, not doing fancy Directory.EnumerateFiles when creating the bundle).

Thanks!

PS: I know that a quicker solution would be to use Mindscape Workbench and bundle the generated js files, I am looking for something that uses what the framework has, maybe also avoiding to have to tell the team to install a tool that people may not like…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:59:28+00:00Added an answer on June 17, 2026 at 2:59 pm

    In the end I went for a HtmlHelper solution for this. Still in early stage but working as I would like. It is detailed in a blog post for the time being.

    Here is the full Helper code in case the blog goes lost…

    public static class HtmlHelperExtensions
    {
        public static MvcHtmlString RenderCoffeeBundle(this HtmlHelper htmlHelper, string virtualPath)
        {
            if (String.IsNullOrEmpty(virtualPath))
                throw new ArgumentException("virtualPath must be defined", "virtualPath");
    
            var list = GetPathsList(virtualPath);
    
            //TODO: Nice and cleaner EliminateDuplicatesAndResolveUrls(list);
    
            var stringBuilder = new StringBuilder();
            foreach (string path in list)
            {
                stringBuilder.Append(RenderScriptTag(path));
                stringBuilder.Append(Environment.NewLine);
            }
            return MvcHtmlString.Create(stringBuilder.ToString());
        }
    
        private static IEnumerable<string> GetPathsList(string virtualPath)
        {
            var list = new List<string>();
    
            if (BundleResolver.Current.IsBundleVirtualPath(virtualPath))
            {
                if (!BundleTable.EnableOptimizations)
                {
                    foreach (var path in BundleResolver.Current.GetBundleContents(virtualPath))
                    {
                        var bundlePath = "~/autoBundle" + ResolveVirtualPath(path.Replace("coffee", "js"));
                        BundleTable.Bundles.Add(new Bundle(bundlePath, new CoffeeBundler()).Include(path));
                        // TODO: Get the actual CustomTransform used in the Bundle
                        // rather than forcing "new CoffeeBundler()" like here
                        list.Add(bundlePath);
                    }
                }
                else
                    list.Add(BundleResolver.Current.GetBundleUrl(virtualPath));
            }
            else
                list.Add(virtualPath);
            return list.Select(ResolveVirtualPath).ToList();
        }
    
        private static string RenderScriptTag(string path)
        {
            return "<script src=\"" + HttpUtility.UrlPathEncode(path) + "\"></script>";
        }
    
        private static string ResolveVirtualPath(string virtualPath)
        {
            return VirtualPathUtility.ToAbsolute(virtualPath);;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Experimenting with Swing, I learnt that there are two ways of using JOptionPane and
Experimenting with android game development. I'm using PNG format for images, and was wondering
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
I am experimenting with Dart. I have created an on click event like so:
I'm experimenting with clojure and am trying to get a feel for using 3rd
Experimenting with a battery monitor icon at the moment in Python using pygtk and
From experimenting with the r.js optimizer, it seems that there is no way for
I am experimenting with a TabHost widget. I did not realise that the TabActivity
I am experimenting with drawing on a canvas using a thread to create a
been experimenting with unordered list UL and i have seem varios examples of using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.