Skip to content

Codepolice

  • ⤫

Problems with gzip when using IIS 7.5 as an Origin server for a CDN

Posted by Judy Alvarez Posted on February 28, 2022March 2, 2022
0

I recently decided to try out my friend Sajals new CDN service over at Turbobytes. While setting this up he pointed out some issues I had with my custom origin domain that I run on IIS. IIS has some problems that many CDN doesn’t like.

The “Via” Header

To begin with, many CDNs send a “Via” header to notify the server that they are a proxy. And for some reason IIS doesn’t serve gzipped content to a server that does this. This means that many CDNs just don’t get gzipped content from IIS and therefore don’t serve gzipped content to your customer. To resolve this you have to change some settings in your applicationHost.config.

<location path="Your Site">
<system.webServer>
<httpCompression noCompressionForHttp10="false" noCompressionForProxies="false" />
</system.webServer>
</location>

The thing to fix the problem with the “Via” header is the two attributes noCompressionForHttp10=” false” and noCompressionForProxies=” false” and they kind of explain themselves. And remember the weirdness with the applicationHost.config to not open them in Notepad++ or any other 32bit based apps. You must edit them with a 64-bit text editor like the built-in notepad in Windows.

curl -I -H Accept-Encoding:gzip,deflate -H Via:Cdn http://example.com/test.css

HTTP/1.1 200 OK
Content-Length: 5648
Content-Type: text/css
Content-Encoding: gzip
Last-Modified: Thu, 14 Jul 2011 16:56:26 GMT
Accept-Ranges: bytes
ETag: "add123f84642cc1:0"
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
Date: Mon, 25 Jun 2012 13:01:34 GMT

IIS doesn’t return the first request gzip by default

Another issue with IIS as an origin server is that it doesn’t return the first request of a file as gzipped. I suppose they figured that for a normal user it’s faster to just return the content and then serve the gzipped version to the next user. But a CDN of course only do one request for the file and then sits happy and serves that file. And if that file is not gzipped then it will stay not gzipped. But there is a fix for this as well. Just modify the same section in applicationHost.config as you’ve edited before and you should be fine. I got lots of help with this question on Stack Overflow.

    <location path="Your Site">
       <system.webServer>
        <httpCompression noCompressionForHttp10="false" noCompressionForProxies="false" />
	<serverRuntime
          frequentHitThreshold="1"
          frequentHitTimePeriod="00:00:05" />
       </system.webServer>
    </location>

The “Vary” Header

Another possible issue is that IIS doesn’t return a “Vary” header if the content is not gzipped. This could cause issues if the first request to your file from any client doesn’t request a gzipped file. Since the vary header is not set then the CDN doesn’t try to fetch a new file. As far as I understand it. I just added a custom header to my web. config. The problem with this is that it ads multiple values in the Vary header when I request gzipped content. I don’t know if this is a problem or not. I’ve asked a question about this on Stack Overflow. I will update here when I get some more answers to this.

<httpProtocol>
<customHeaders>
<remove name="Vary"></remove>
<add name="Vary" value="Accept-Encoding" />
</customHeaders>
</httpProtocol>
curl -I http://example.com/test.css

HTTP/1.1 200 OK
Content-Length: 18241
Content-Type: text/css
Last-Modified: Thu, 14 Jul 2011 16:56:26 GMT
Accept-Ranges: bytes
ETag: "add123f84642cc1:0"
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
Date: Tue, 26 Jun 2012 12:04:42 GMT

Problem with multiple Vary values.

curl -I -H Accept-Encoding:gzip,deflate http://example.com/theme.css
HTTP/1.1 200 OK
Content-Length: 4445
Content-Type: text/css
Content-Encoding: gzip
Last-Modified: Thu, 14 Jul 2011 16:56:26 GMT
Accept-Ranges: bytes
ETag: "059d5f74642cc1:0"
Vary: Accept-Encoding,Accept-Encoding
Server: Microsoft-IIS/7.5
Date: Tue, 26 Jun 2012 12:03:00 GMT
Categories: JavascriptTagged: asp net 3.5, asp net authorization, asp net barcode generator, asp net book pdf, asp net core crud operations example, asp net core vs asp net framework, asp net development agencies, asp net framework vs core, asp net generate pdf from html, asp net grid, asp net identity core, asp net interview questions and answers for experienced, asp net jobs in bangalore, asp net mvc caching, asp net mvc development company, asp net mvc sample application, asp net mysql, asp net pdf report generation, asp net rapid application development, asp net sending e mail, asp net the complete reference by matthew macdonald pdf free download, asp net vb net, asp net vs vb net, asp net web development india, asp net web forms tutorial c#, difference between asp net and asp net mvc, editable gridview in asp net, hcso hctx net inmateinfo asp, master page in asp net, what is cms in asp net

Post navigation

Previous Previous post: Query the MySQL / WordPress Database from an ASP.NET site
Next Next post: What I Love So Far With Visual Studio

Related Posts

  • Building JavaScript tools in a single HTML file

    #​765 — December 12, 2025 Read on the Web JavaScript Weekly Useful Patterns for Building HTML Tools — In many situations, you don’t need a full-on framework to build useful tools; just HTML, JavaScript and CSS in a single file will do the job fine. Simon’s become a bit of an expert by rolling out

    Posted by Posted on December 12, 2025
    0
  • How the Seattle Times is using pnpm

    #​604 — December 9, 2025 Read on the Web 🗓️ A quick notice that Node Weekly will be moving to Thursdays in January 2026, as part of a schedule reshuffle for most of our newsletters. We still have one more week before the Christmas break, though, so we’ll be back next Tuesday with our 2025 roundup!__Your editor,

    Posted by Posted on December 10, 2025
    0
  • What’s the story? JavaScript’s 30!

    #​764 — December 5, 2025 Read on the Web JavaScript Weekly 🎉  JavaScript Turns 30 Years Old  🎉 Back in May 1995, a 33 year old Brendan Eich built the first prototype of JavaScript in just ten days, originally codenamed Mocha (and then LiveScript). On December 4, 1995, Netscape and Sun Microsystems officially announced ‘JavaScript’ in a

    Posted by Posted on December 5, 2025
    0
  • Comparing performance across Node versions and ARM vs x86

    #​603 — December 2, 2025 Read on the Web Tinybench 6.0: A Tiny, Simple Benchmarking Library — Uses whatever precise timing capabilities are available (e.g. process.hrtime or performance.now). You can then benchmark whatever functions you want, specify how long or how many times to benchmark for, and get a variety of stats in return –

    Posted by Posted on December 2, 2025
    0
  • Algorithms visualized and demonstrated in JavaScript

    #​763 — November 28, 2025 Read on the Web JavaScript Weekly Over 150 Algorithms and Data Structures Demonstrated in JS — Examples of many common algorithms (e.g. bit manipulation, Pascal’s triangle, Hamming distance) and data structures (e.g. linked lists, tries, graphs) with explanations. Available in eighteen other written languages too. Oleksii Trekhleb et al. TypeScript: From

    Posted by Posted on November 28, 2025
    0
  • Guess who’s back, back again? Shai-Hulud.

    #​602 — November 25, 2025 Read on the Web How a Summer in Abruzzo Helped Bring Type Stripping to Node.js — Node.js TSC member and committer Marco tells the personal tale of what it took to bring type stripping (now considered stable) to Node. It’s neat to get the back story. He’s now working on

    Posted by Posted on November 25, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • Building JavaScript tools in a single HTML file
  • How the Seattle Times is using pnpm
  • What’s the story? JavaScript’s 30!
  • Comparing performance across Node versions and ARM vs x86
  • Algorithms visualized and demonstrated in JavaScript
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice