views:

33

answers:

3

I was thinking javascript_include_tag with :cache option would g-zip the combined javascript file automatically:


<%= javascript_include_tag 'j1.js', 'j2.js', 'j3.js', :cache => 'js_all' %>

But it just generate a file which simply combined all those javascript files in plain text mod;
Then how to g-zip the combinded file automatically?
Is there a build in option in 'javascript_include_tag' for that?

Or,
How do you fix the g-zip prolem?
By hand?
Writing ruby codes which excute system 'gzip' command?
...
What would do on it?


I use nginx as the server;

+1  A: 

Generally you would let your server handle the gziping for you. Apache, for example, can be configured to handle this automatically.

Toby Hede
+2  A: 

I agree with Toby, that it is usual to configure your webserver to perform gzipping for applicable files.

For Apache take a look at mod_deflate

Here is a typical Apache config excerpt

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml application/rss+xml application/json text/css text/javascript application/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Paul Groves
+1  A: 

Jammit is my package manager of choice. Along with the apache configuration mentioned, it will create the gzip'd files for you to serve if it's supported. Generally though, you can have apache just do it on the fly as mentioned above.

brad