[英]Why gulp-gzip and can I serve gzipped content without configuring the server?
I ran into a dilemma lately as I was exploring the various plugins for gulp. 我最近在探索各种插件时陷入了困境。 One of them was
gulp-gzip
and till then, I have never thought about compressing my files. 其中一个是
gulp-gzip
,直到那时,我从未想过压缩我的文件。 I got gulp-gzip
to work correctly and spit out gzipped versions of my HTML, CSS and JS files but then, what next? 我得到
gulp-gzip
正常工作并吐出我的HTML,CSS和JS文件的gzip压缩版本然后,下一步是什么?
I googled around and found that most articles talk about configuring the server to send gzipped versions of the content automatically to the client upon request. 我搜索了一下,发现大多数文章都谈到配置服务器以根据请求自动向客户端发送gzip压缩版本的内容。 But then, I kind of don't seem to understand the purpose of gzipping locally.
但是,我似乎并不理解本地gzipping的目的。
So, my questions are: 所以,我的问题是:
gulp-gzip
without configuring my server? gulp-gzip
提供的gzip压缩内容吗? .gz
extension and link to my CSS and JS files using the same? .gz
扩展名并使用相同的链接到我的CSS和JS文件吗? .gz
files? .gz
文件在本地测试吗? gulp-gzip
in a development environment if the server can be configured to do it automatically? gulp-gzip
在开发环境中的用途是什么? Most servers have an option to serve statically pre-compressed files if a *.gz
version exists, ie when user requests foo.css
, the server will check if foo.css.gz
exists and use it. 如果存在
*.gz
版本,大多数服务器都可以选择提供静态预压缩文件,即当用户请求foo.css
,服务器将检查foo.css.gz
存在并使用它。
It requires server support (the server has to set appropriate HTTP headers), so it won't work with the file://
protocol and may not work on every server. 它需要服务器支持(服务器必须设置适当的HTTP头),因此它不能与
file://
协议一起使用,并且可能无法在每台服务器上运行。
In URLs you have to refer to the base filename (do not link to .gz
directly). 在URL中,您必须引用基本文件名(不要直接链接到
.gz
)。
Compressing files ahead of time may be better: 提前压缩文件可能会更好:
Just be careful when you deploy files to the server to update both *.css
and *.css.gz
at the same time, otherwise you may be surprised that you sometimes see old version of the file. 将文件部署到服务器以同时更新
*.css
和*.css.gz
时要小心,否则您可能会惊讶于您有时会看到旧版本的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.