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

  • SEARCH
  • Home
  • 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 8152871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:50:14+00:00 2026-06-06T15:50:14+00:00

In trying to keep with unobtrusive JavaScript guidelines I moved all the JavaScript out

  • 0

In trying to keep with unobtrusive JavaScript guidelines I moved all the JavaScript out of each of my views and into a separate .js files.

However, within 1 view I need to dynamically create some JavaScript variables so these are inserted into the ViewBag and rendered directly into the view:

    $(document).ready(function () {
        @(ViewBag.PrePop)
        @(ViewBag.PreDiscount)
    });

This works fine until I had a go at using the new ASP.net bundling and minification feature.

Bundling all these small external JavaScript files together and then calling the combined script from every page means that every page (other than the one that contains the ViewBag emitted variables) has a variable reference error:

Uncaught ReferenceError: quotes is not defined 

So this basically means I can’t bundle this particular JavaScript file.

However, I would like to minify it. To do this, do I just declare a bundle that only contains the one JavaScript file:

bundles.Add(new ScriptBundle("~/bundles/mypagescript").Include(
            "~/Scripts/mypagescript.js"));

Or is there another way to perform solely minification?

  • 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-06T15:50:15+00:00Added an answer on June 6, 2026 at 3:50 pm

    Yep, currently we don’t really expose any methods for you to easily call in to Optimization just to minify a string (you could do it via an instance of JsMinify.Process if you really wanted) i.e.:

    string js = "//I am a comment\r\nfoo = bar;\r\nfoo = yes;";
    JsMinify jsmin = new JsMinify();
    BundleContext context = new BundleContext();
    BundleResponse response = new BundleResponse(js, null);
    response.Content = js;
    jsmin.Process(context, response);
    Assert.AreEqual("foo=bar,foo=yes", response.Content);
    

    But what you suggest is probably best (create a bundle of one file).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to keep a dictionary of open files for splitting data into individual
I'm trying to keep my static files in a separate branch so that I
I'm trying to keep my code clean and keep the number of files down.
I'm trying to keep track of a set of files, which may have the
So I'm trying to figure out how to do this cleanly. Trying to keep
I am trying to use the JavaScript Module Pattern and I run into a
Trying to keep a box centered vertically within another box. I know there's css
Trying to keep all the presentation stuff in the xhtml on this project and
I am trying to keep my project self-contained, with all major 3rd party library
I am trying to figure out the best way to acompish unobtrusive forms for

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.