title: Using gzip compression in Sinatra with Ruby
body: <p>Note: I had another similar question about how to GZIP data using Ruby's <code>zlib</code> which <em>technically</em> was answered and I didn't feel I could start evolving the question since it had been answered so although this question is related it is not the same...</p>
  
  <p>The following code (I believe) is GZIP'ing a static CSS file and storing the results in the <code>result</code> variable. But what do I do with this in the sense: how can I send this data back to the browser so it is recognised as being GZIP'ed rather than the original file size (e.g. when checking my YSlow score I want to see it correctly marking me for making sure I GZIP static resources).</p>
  
  <pre><code>z = Zlib::Deflate.new(6, 31)
  z.deflate(File.read('public/Assets/Styles/build.css'))
  z.flush
  @result = z.finish # could also of done: result = z.deflate(file, Zlib::FINISH) 
  z.close
  </code></pre>
  
  <p>...one thing to note is that in my previous question the respondent clarified that <code>Zlib::Deflate.deflate</code> will not produce gzip-encoded data. It will only produce zlib-encoded data and so I would need to use <code>Zlib::Deflate.new</code> with the <code>windowBits</code> argument equal to 31 to start a gzip stream.</p>
  
  <p>But when I run this code I don't actually know what to do with the <code>result</code> variable and its content. There is no information on the internet (that I can find) about how to send GZIP encoded static resources (like JavaScript, CSS, HTML etc) to the browser, this making the page load quicker. It seems every Ruby article I read is based on someone using Ruby on Rails!!?</p>
  
  <p>Any help really appreciated.</p>