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 8180579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:14:36+00:00 2026-06-07T00:14:36+00:00

I am using the new System.Web.Optimization and have created a bundle like this: bundles.Add(New

  • 0

I am using the new System.Web.Optimization and have created a bundle like this:

bundles.Add(New ScriptBundle("~/bundles/BaseJS").Include(
                "~/Resources/Core/Javascripts/jquery-1.7.1.js",
                "~/Resources/Core/Javascripts/jquery-ui-1.8.16.js",
                "~/Resources/Core/Javascripts/jquery.validate.js",
                "~/Resources/Core/Javascripts/jquery.validate.unobtrusive.js",
                "~/Resources/Core/Javascripts/jquery.unobtrusive-ajax.js"))

and in my view I have added this

@System.Web.Optimization.Scripts.Render("~/bundles/BaseJS")

In fiddler the URL comes across with an expires header of 1 year in the future and a content type of text/javascript

In the web.config I have some code for gzip that is working on static JS files but it doesn’t seem to on the minified bundles.

<staticContent>
  <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
  <remove fileExtension=".js"/>
  <mimeMap fileExtension=".js" mimeType="text/javascript"/>
</staticContent>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
  <dynamicTypes>
    <add mimeType="text/*" enabled="true"/>
    <add mimeType="text/javascript" enabled="true"/>
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true"/>
    <add mimeType="text/javascript" enabled="true"/>
  </staticTypes>
</httpCompression>

Is there a way to make the render bundle gzip the content?

  • 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-07T00:14:37+00:00Added an answer on June 7, 2026 at 12:14 am

    As you noted, creating a custom bundle transform by creating a class that implements IBundleTransform is the right way to go. For example, the following is an example bundle transform that uses the SharpZipLib (via NuGet) to do GZip compression:

    public class GZipTransform : IBundleTransform 
    {
        string _contentType;
    
        public GZipTransform(string contentType)
        {
            _contentType = contentType;
        }
    
        public void Process(BundleContext context, BundleResponse response)
        {
            var contentBytes = new UTF8Encoding().GetBytes(response.Content);
    
            var outputStream = new MemoryStream();
            var gzipOutputStream = new GZipOutputStream(outputStream);
            gzipOutputStream.Write(contentBytes, 0, contentBytes.Length);
    
            var outputBytes = outputStream.GetBuffer();
            response.Content = Convert.ToBase64String(outputBytes);
    
    
            // NOTE: this part is broken
            context.HttpContext.Response.Headers["Content-Encoding"] = "gzip";
            response.ContentType = _contentType ;
        }
    }
    

    Now, here’s the unfortunate part – in testing this sample, I uncovered a bug that will keep it from working. The original design expected that folks would do pretty simple things – and as such, BundleResponse exposes properties that allow you to set the content (more specifically, string content) and the content type. The BundleContext exposes a property of HttpContext, which would lead a reasonable person to believe that additional properties of a response could be set there (as shown above). However, this is misleading for 2 reasons:

    1. Bundle transforms are run as a part of creating the bundle – and creating the bundle happens the first time it is referenced (not dereferenced, as in, the browser follows the src attribute in a script tag – but referenced, as in, the view calls the Scripts.Render helper method). In my example above, this means that a content-encoding header with a value of gzip will be set on the first page with a view that uses bundling’s helper methods to generate a link – and if the actual HTTP content is not gzipped, you’ll get an error since the browser can’t decode the HTTP content.

    2. Even if #1 weren’t an issue, the bundle is put immediately put into the ASP.NET cache after it is created – so this code path will only be executed once.

    We’re taking a hard look at the design in the next version of framework to enable you to specify all (ideally) aspects of the HTTP response message that is free of the HTTP context (meaning it’s easily cachable).

    One additional note. To supply custom bundle transforms, you’ll need to fall back to creating an instance of Bundle rather than ScriptBundle/StyleBundle. Those classes are really just shorthand types for bundles with preconfigured bundle transforms. To create a bundle based on Bundle, you would do something like the following:

    var jqueryBundle = new Bundle("~/bundles/jqueryall", new GZipTransform("text/javascript"));
    jqueryBundle.Include("~/Scripts/jquery-1.*",
        "~/Scripts/jquery-ui*",
        "~/Scripts/jquery.unobtrusive*",
        "~/Scripts/jquery.validate*");
    bundles.Add(jqueryBundle);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code: Dim cListItems As New System.Collections.Generic.List(Of Combobox_values) cListItems.Add(New Combobox_values(One, 1)) cListItems.Add(New
Using the .NET System.ServiceModel.Syndication classes... I would like to add a new SyndicationElementExtension to
I have some code using a System.Transactions.TransactionScope , that creating a new instance of
I've referenced System.Xml: using System.Xml; Then in this line: XmlDocument xdoc = new XmlDocument();
i have a handler for download files like below : using System; using System.Collections.Generic;
I'm creating DIV controls from code behind using this code - System.Web.UI.HtmlControls.HtmlGenericControl dynDiv =
I'm using system.Timers.Timer to create a timer. public System.Timers.Timer timer = new System.Timers.Timer(200); private
I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get
I'm starting up a new embedded system design using FreeRTOS. My last one used
I am using System.Timers in my program. As we know each interval new thread

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.