代码之家  ›  专栏  ›  技术社区  ›  Ricardo Acras

如何使用mongrel压缩http响应

  •  3
  • Ricardo Acras  · 技术社区  · 16 年前

    我有一个rails应用程序,它大量使用js(总共超过1MB)。我想压缩它们,以减少网站的整体加载时间。

    我做了一个快速搜索,发现大多数浏览器都接受压缩内容。

    我想知道我该怎么做才能让我的rails应用程序发送压缩内容,从而改善用户体验。

    2 回复  |  直到 16 年前
        1
  •  4
  •   Michael    16 年前

    您应该始终让代理到您的杂种的web服务器处理静态内容的提供和压缩。对静态内容的请求永远不应该传递给杂种。

    例如,使用nginx,只需在配置文件中添加gzip指令即可。

    http://topfunky.net/svn/shovel/nginx/conf/nginx.conf

    # output compression saves bandwidth 
      gzip            on;
      gzip_http_version 1.0;
      gzip_comp_level 2;
      gzip_proxied any;
      gzip_types      text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
        2
  •  2
  •   Community CDub    8 年前

    已经提出并回答了两个类似的问题。希望那里的内容也会有所帮助。

    How can I pre-compress files with mod_deflate in Apache 2.x?

    How do I gzip webpage output with Rails?