压缩Rails资产和Nginx Gzip [英] Compressing rails assets and nginx gzip

查看:74
本文介绍了压缩Rails资产和Nginx Gzip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用rake assets:precompile压缩了rails资产,是否必须配置nginx来压缩资产(将gzip设置为on)?我的意思是说有意义吗?性能会好还是坏?谢谢!

Do I have to configure nginx to compress assets (gzip set to on) if I have compressed rails assets with rake assets:precompile? I mean does it make sense or not? Will performance better or worse? Thank you!

推荐答案

不,您没有.它们不是同一种压缩方式.运行rake assets:precompile时,您真正要做的就是将一堆文件合并为一个文件并将其转储到磁盘.实际上,根据官方文档,它是两个文件:

No, you do not. They are not the same kind of compression. When you run rake assets:precompile, all you're really doing is joining a bunch of files into one file and dumping it to the disk. Actually, according to the official documentation, it is two files:

预编译文件时,Sprockets还会创建一个gzip(.gz)文件 您资产的版本. Web服务器通常配置为使用 适度的压缩比是一个折衷方案,但是由于预编译 发生一次,Sprockets使用最大压缩率,因此 将数据传输的大小减小到最小.在另一 一方面,可以将Web服务器配置为提供压缩内容 直接从磁盘,而不是缩小未压缩的文件 自己.

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压缩,这是真正的压缩(不仅是串联文件),它减少了您必须传输的数据量,但是消耗处理器能力(压缩和解压缩).根据页面大小和(以及用户的)硬件,它可能会极大地改善您的网站.

This is important for you, because it allows you to use gzip, if you want, but it does not force you to do so. Gzip compression, which is real compression (not just concatenating files) reduces the amount of data you have to transfer, but at the expense of processor power (compressing and decompressing). It is likely to fairly dramatically improve your site, depending on page sizes and your (and your user's) hardware.

这篇关于压缩Rails资产和Nginx Gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆