{"id":16,"date":"2009-05-06T11:51:10","date_gmt":"2009-05-05T23:51:10","guid":{"rendered":"http:\/\/eion.robbmob.com\/blog\/?p=16"},"modified":"2009-05-11T07:54:40","modified_gmt":"2009-05-10T19:54:40","slug":"gzip-encoding","status":"publish","type":"post","link":"https:\/\/eion.robbmob.com\/blog\/2009\/05\/06\/gzip-encoding\/","title":{"rendered":"Gzip Encoding"},"content":{"rendered":"<p>On PHP pages that I get control over, one of the first things I do is add Gzip encoding.  This compresses the text on the page for browsers that can handle it, and really reduces network traffic, speeding up page load\/download times on dial-up (well, and broadband) connections significantly.<\/p>\n<p>On PHP this is really easy, its just one line of code at the top of the page:<\/p>\n<pre>ob_start('ob_gzhandler');<\/pre>\n<p>But until now, I had trouble finding out how to do this for .NET sites.  All I could find was that you can enable it server-wide on IIS but now I found this handy bit of code that can go at the top of your .NET pages.<\/p>\n<pre>string AcceptEncoding = HttpContext.Current.Request.Headers[\"Accept-Encoding\"];\r\nif (!string.IsNullOrEmpty(AcceptEncoding) &amp;&amp; AcceptEncoding.Contains(\"gzip\"))\r\n{\r\n    HttpContext.Current.Response.AppendHeader(\"Content-Encoding\", \"gzip\");\r\n    HttpContext.Current.Response.AppendHeader(\"Vary\", \"Content-Encoding\");\r\n    HttpContext.Current.Response.Filter = new System.IO.Compression.GZipStream(HttpContext.Current.Response.Filter, System.IO.Compression.CompressionMode.Compress);\r\n}<\/pre>\n<p>And that&#8217;s it.  Tasty Gzip encoding for all.  The next step is testing it, which I use the mod_gzip_test site for.  You can see an example of the changes we made to gameplayer.co.nz (a .net site) <a href=\"http:\/\/www.whatsmyip.org\/http_compression\/?url=aHR0cDovL3d3dy5nYW1lcGxheWVyLmNvLm56LzEyMDlhMS5wYWdl\" target=\"_blank\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>On PHP pages that I get control over, one of the first things I do is add Gzip encoding. This compresses the text on the page for browsers that can handle it, and really reduces network traffic, speeding up page load\/download times on dial-up (well, and broadband) connections significantly. On PHP this is really easy, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3CEsE-g","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/posts\/16"}],"collection":[{"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eion.robbmob.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}