Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure CDN + Asp.net MVC Cloud Service compression for bundles not working

I am using Azure CDN which is pointing to my Azure Cloud Service. I have enabled bundling for my JS and CSS files, and in BundleConfig I have set bundles.UseCdn = true.

Everything is working fine, except that JS & CSS bundles returned via CDN are not compressed. If I am not using CDN, bundles are returned compressed (I can see that Content-Encoding is gzip).

I have enabled compression on my CDN as you can see in pic below:

enter image description here

And in my ASP.net MVC web.config compression is also enabled, and it looks like this:

 <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  <httpCompression>
    <dynamicTypes>
    <clear/>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/x-javascript" enabled="true" />
      <add mimeType="text/javascript" enabled="true" />
      <add mimeType="text/css" enabled="true" />
      <add mimeType="application/json" enabled="true" />

      <!-- HERE -->
      <add mimeType="image/svg+xml" enabled="true" />
      <add mimeType="image/png" enabled="true" />
      <add mimeType="image/jpg" enabled="true" />
      <add mimeType="image/jpeg" enabled="true" />
      <add mimeType="application/font-woff2" enabled="true" />
      <add mimeType="application/x-font-ttf" enabled="true" />
      <add mimeType="application/octet-stream" enabled="true" />
      <!-- HERE -->

      <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
    <clear/>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/x-javascript" enabled="true" />
      <add mimeType="text/javascript" enabled="true" />
      <add mimeType="text/css" enabled="true" />
      <add mimeType="application/atom+xml" enabled="true" />
      <add mimeType="application/xaml+xml" enabled="true" />

      <!-- HERE -->
      <add mimeType="image/png" enabled="true" />
      <add mimeType="image/jpg" enabled="true" />
      <add mimeType="image/jpeg" enabled="true" />
      <add mimeType="application/font-woff2" enabled="true" />
    <add mimeType="application/x-font-ttf" enabled="true" />
      <add mimeType="application/octet-stream" enabled="true" />
      <!-- HERE -->

      <add mimeType="*/*" enabled="false" />
    </staticTypes>
  </httpCompression>

Interestingly, for same CDN profile (but other endpoint) pictures do have Content-Encoding: gzip, so it seems that compression works fine on CDN also.

This SO answer suggested adding smth. like &group=smth.js at the end of CDN URL, but that din't help.

So what am I doing wrong?

like image 249
hyperN Avatar asked Oct 15 '17 12:10

hyperN


1 Answers

According to your description, I created my MVC web application to check this issue and I did not configure urlCompression under my web.config file.

enter image description here

Without Azure CDN, the css/javascript would be compressed.

For test, I just CDN my whole web app via Azure CDN as follows:

enter image description here

enter image description here

Note: The Compression is enable by default and the formats to compress are the default settings.

Then, access the css/javascript links, they would be compressed as expected.

enter image description here

like image 183
Bruce Chen Avatar answered Sep 19 '22 21:09

Bruce Chen