In rails, how to g-zip a combined javascript file which generated by the 'javascript_include_tag'?
I was thinking javascript_include_tag with :cache option wo开发者_JAVA百科uld 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;
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
Generally you would let your server handle the gziping for you. Apache, for example, can be configured to handle this automatically.
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.
精彩评论