如果我用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是真正的压缩(不仅仅是连接文件),可以减少传输数据量,而是牺牲处理器的功率(压缩和解压缩).根据页面大小和您的(和您的用户的)硬件,可能会显着提高您的网站.