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

  • Ways to remove event listeners

    #​624 — February 3, 2023 Read on the Web JavaScript Weekly You’ve Got Options for Removing Event Listeners — Unnecessary event listeners can cause all sorts of odd problems so it’s good to clean them up when you don’t need them anymore. How? There are several approaches and Alex looks at their pros and cons. (once

    Posted by Posted on February 3, 2023
    0
  • SQL in your JavaScript

    #​472 — February 2, 2023 Read on the Web AlaSQL.js 3.0: Isomorphic JavaScript SQL Database — A SQL database you can use in Node.js and the browser. The interesting bit, for me, is how it opens up the idea of using SQL to query JavaScript objects – as in this example. “The library adds the

    Posted by Posted on February 2, 2023
    0
  • Astro 2.0 and TypeScript 5.0 beta

    #​623 — January 27, 2023 Read on the Web JavaScript Weekly Astro 2.0: The Next-Gen ‘Islands’-Oriented Web Framework — 2.0 includes hybrid rendering (mixing of SSR and SSG outputs), type safety for Markdown & MDX, and an upgrade to Vite 4.0. Astro is worth exploring when performance is key as it works with popular frameworks

    Posted by Posted on January 27, 2023
    0
  • Automating the desktop with Node

    #​471 — January 26, 2023 Read on the Web Nut.js 3.0: Use Node for Desktop Automation — Take control of your desktop environment (Windows, macOS or Linux) from code with control over keyboard and pointer, plus you get some image matching possibilities too. Open source but with optional sponsor-only extension packages. GitHub repo and what’s new

    Posted by Posted on January 26, 2023
    0
  • Why document.write() is bad

    #​622 — January 20, 2023 Read on the Web JavaScript Weekly Why Not document.write()? — Many moons ago, document.write was a mainstay of client-side JavaScript code, but it’s long been considered a bad practice – why? Harry digs in, noting that it “guarantees both a blocking fetch and a blocking execution, which holds up the

    Posted by Posted on January 20, 2023
    0
  • We’re going on a memory leak hunt

    #​470 — January 19, 2023 Read on the Web Fixing a Memory Leak in a Production Node App — Kent encountered a variety of weird memory and CPU usage spikes in his Node-powered app and decided to figure out what was going on. This post walks through his complete journey, with plenty of side problems

    Posted by Posted on January 19, 2023
    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
  • Ways to remove event listeners
  • SQL in your JavaScript
  • Astro 2.0 and TypeScript 5.0 beta
  • Automating the desktop with Node
  • Why document.write() is bad
https://flatlogic.com/generator
COPYRIGHT © 2023 - Codepolice