Gzip compression of .rb and .rhtml files

I haven’t been able to find the answer to my question by Googling,
possibly because “gzip” is everywhere on the web.

The context of my question is: deploying a Ruby on Rails application
onto a system with limited (flash) storage. I am aware of the various
compressed filesystems available, but I’m considering other
approaches.

Is it possible to deploy a Rails application with all/some of it’s
source .rb, .rhtml, .css and .js files gzipped to save space?

e.g. If foo.rb can’t be found, foo.rb.gz should be read instead. So
long as the .rb and .rhtml files do need to be accessed randomly,
there should be no need to gunzip the file in place.

These are text files, so 3:1 compression may be possible.

I have a feeling (as functions are first class objects in Ruby) that
it may be possible to redefine a few IO functions to achieve this.
Any hints would be welcome.

Regards,

Chris.

Chris D. wrote:

I haven’t been able to find the answer to my question by Googling,
possibly because “gzip” is everywhere on the web.

The context of my question is: deploying a Ruby on Rails application
onto a system with limited (flash) storage. I am aware of the various
compressed filesystems available, but I’m considering other
approaches.

Is it possible to deploy a Rails application with all/some of it’s
source .rb, .rhtml, .css and .js files gzipped to save space?

Try looking at changing methods

def read_template_file(template_path, extension)

or

def render_template(template_extension, template, file_path = nil,
local_assigns = {}) #:nodoc:

in

actionpack/lib/action_view/base.rb

e.g. If foo.rb can’t be found, foo.rb.gz should be read instead. So
long as the .rb and .rhtml files do need to be accessed randomly,
there should be no need to gunzip the file in place.

You lost me with that one.

I’m looking at ActionPack version 1.12.5 here. You may have a different
version.

Maybe it’s a one-liner.

Stephan

On Feb 27, 11:02 pm, Stephan W. [email protected]
wrote:

source .rb, .rhtml, .css and .js files gzipped to save space?
in

actionpack/lib/action_view/base.rb

e.g. If foo.rb can’t be found, foo.rb.gz should be read instead. So
long as the .rb and .rhtml files do need to be accessed randomly,
there should be no need to gunzip the file in place.

You lost me with that one.

If you just read a short file into memory, you can just gunzip the
contents as you read them, not changing anything on disk.

If you need random access (read or write), you would need to gunzip
the file to temporary storage (perhaps the disk), perform the
operations, then gzip the file up again when finished.

I’m looking at ActionPack version 1.12.5 here. You may have a different
version.

Maybe it’s a one-liner.

Stephan


Posted viahttp://www.ruby-forum.com/.

Thanks for your reply,

Chris.

I think you’ll find the Output Compression plugin [
http://wiki.rubyonrails.org/rails/pages/Output+Compression+Plugin] does
what
you’re looking for. I was playing around with it and looking at the
results
in Firebug and it looked good.

RSL

On 28 Feb 2007, at 13:47, Russell N. wrote:

I think you’ll find the Output Compression plugin [http://
wiki.rubyonrails.org/rails/pages/Output+Compression+Plugin] does
what you’re looking for. I was playing around with it and looking
at the results in Firebug and it looked good.

If you want output compression for serving files, you can just use
Apache’s deflate module:

Deflate

AddOutputFilterByType DEFLATE text/html text/plain text/css text/
javascript

… text/xml application/xml application/xhtml+xml text/javascript

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

However, the original poster was looking for a way to compress his
files on the server itself, decompressing them in memory before
sending it through the ruby interpreter.

Best regards

Peter De Berdt

On 28 Feb 2007, at 17:31, Stephan W. wrote:

Why wouldn’t you use a compression-file-system?
My impression is that the original poster is trying to host a Rails
application on a very small shared hosting account (or a free hosting
account). The total size of a fairly large Rails project rapidly
exceeds 50 MB. My advise if this is indeed the case would be to just
pay a little bit more for a decent hosting provider instead of trying
to solve a problem that in the end will cost you more (timewise) then
it will cost you to get a better hosting account.

Best regards

Peter De Berdt

Chris D. wrote:

On Feb 27, 11:02 pm, Stephan W. [email protected]
wrote:

source .rb, .rhtml, .css and .js files gzipped to save space?
in

actionpack/lib/action_view/base.rb

e.g. If foo.rb can’t be found, foo.rb.gz should be read instead. So
long as the .rb and .rhtml files do need to be accessed randomly,
there should be no need to gunzip the file in place.

You lost me with that one.

If you just read a short file into memory, you can just gunzip the
contents as you read them, not changing anything on disk.

If you need random access (read or write), you would need to gunzip
the file to temporary storage (perhaps the disk), perform the
operations, then gzip the file up again when finished.

I see now.

Actually you may be able to redefine the File methods that come into
play, where File.exists? returns also true if filename + .gz exists, and
File.read will read from filename + .gz if filename doesn’t exist.

This would then be on the Ruby level, not Rails.

Don’t know all the methods that would need redefining. Don’t know how
the Ruby interpreter loads files (through the File class, or not?)

Why wouldn’t you use a compression-file-system?

Stephan

I’m looking at ActionPack version 1.12.5 here. You may have a different
version.

Maybe it’s a one-liner.

Stephan


Posted viahttp://www.ruby-forum.com/.

Thanks for your reply,

Chris.