ruby-on-rails – 压缩rails资产和nginx gzip

如果我用rake资源压缩了rails资产,我必须配置Nginx来压缩资产(gzip设置为on):预编译?我的意思是没有意义吗?会表现好还是差?谢谢!

解决方法

你不可以.他们不是一样的压缩.当您运行rake资产:预编译时,您正在做的所有事情是将一堆文件加入到一个文件中并将其转储到磁盘.其实根据 official documentation,它是两个文件

When files are precompiled,Sprockets also creates a gzipped (.gz)
version of your assets. Web servers are typically configured to use a
moderate compression ratio as a compromise,but since precompilation
happens once,Sprockets uses the maximum compression ratio,thus
reducing the size of the data transfer to the minimum. On the other
hand,web servers can be configured to serve compressed content
directly from disk,rather than deflating non-compressed files
themselves.

这对你很重要,因为它允许你使用gzip,如果你愿意,但它不强制你这样做. Gzip compression是真正的压缩(不仅仅是连接文件),可以减少传输数据量,而是牺牲处理器的功率(压缩和解压缩).根据页面大小和您的(和您的用户的)硬件,可能会显着提高您的网站.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...