Note. I had another similar question about how GZIP data using Ruby zlib was given a technical answer to and I didn’t feel that I could start developing this question since it was answered, although this question is related to this same thing ...
The following code (I believe) is a GZIP'ing static CSS file and storing the results in the result variable. But what should I do with this in the sense: how can I send this data back to the browser so that it is recognized as GZIP'ed, and not the original file size (for example, when checking my YSlow account I want it to be correctly labeled to make sure static resources are gzip).
z = Zlib::Deflate.new(6, 31) z.deflate(File.read('public/Assets/Styles/build.css')) z.flush @result = z.finish
... It should be noted that in my previous question the defendant explained that Zlib::Deflate.deflate will not generate gzip-encoded data. It will only generate zlib-encoded data, so I will need to use Zlib::Deflate.new with a windowBits argument of 31 to start the gzip stream.
But when I run this code, I really don't know what to do with the result variable and its contents. There is no information on the Internet (what I can find) on how to send static resources encoded in GZIP to the browser (for example, JavaScript, CSS, HTML, etc.), which speeds up page loading. It seems that every Ruby article I read is based on who uses Ruby on Rails !!?
Any help really appreciated.
ruby gzip zlib sinatra
Integratedralist
source share