在 IIS7 上使用 MVC3 时如何启用 gzip 压缩? [英] How do I enable gzip compression when using MVC3 on IIS7?
问题描述
有人知道如何在 MVC 3 中启用 gzip 压缩吗?我使用的是 IIS7.
Google Chrome 审核结果:
<块引用>- 启用 gzip 压缩 (4)
- 使用 gzip 压缩以下资源可以将其传输大小减少约三分之二 (~92.23KB):
- /mydomain/可以节省 ~1.53KB
- jquery-1.4.4.min.js 可以节省 ~51.35KB
- Cufon.js 可以节省 ~11.89KB
- Futura.js 可以节省约 27.46KB
您可以通过您的 web.config
文件配置压缩如下:
<urlCompression doStaticCompression="true" doDynamicCompression="true"/></system.webServer>
您可以在 iis.net/ConfigReference 找到此配置元素的文档.这相当于:
- 打开 Internet 信息服务(IIS 管理器)
- 在左侧的树视图中导航,直到到达要修改的虚拟目录
- 选择适当的虚拟目录,使右侧窗格的标题成为所述虚拟目录的名称.
- 在右侧窗格的IIS"下选择压缩"
- 勾选两个选项并选择最右侧操作"下的应用".
注意:(如评论中指出的)您需要确保安装了 Http 动态压缩,否则设置 doDynamicCompression="true"
将没有任何效果.最快的方法是:
- 开始 > 输入
optionalfeatures
(这是进入打开或关闭 Windows 功能"窗口的最快方式) - 在Windows 功能"树视图中导航到 Internet 信息服务 > 万维网服务 > 性能功能
- 确保勾选动态内容压缩"
- 点击确定"并等待 Windows 安装组件
Does anybody know how to enable gzip compression in MVC 3? I'm using IIS7.
Google Chrome Audit's result:
- Enable gzip compression (4)
- Compressing the following resources with gzip could reduce their transfer size by about two thirds (~92.23KB):
- /mydomain/ could save ~1.53KB
- jquery-1.4.4.min.js could save ~51.35KB
- Cufon.js could save ~11.89KB
- Futura.js could save ~27.46KB
You can configure compression through your web.config
file as follows:
<system.webServer>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
You can find documentation of this configuration element at iis.net/ConfigReference. This is the equivalent of:
- Opening Internet Information Services (IIS Manager)
- Navigating through the tree-view on the left until you reach the virtual directory you wish to modify
- Selecting the appropriate virtual directory so that the title of the right-hand pane becomes the name of said virtual directory.
- Choosing "Compression" under "IIS" in the right-hand pane
- Ticking both options and choosing "Apply" under "Actions" on the far right.
Note: (As pointed out in the comments) You need to ensure that Http Dynamic Compression is installed otherwise setting doDynamicCompression="true"
will not have any effect. The quickest way to do this is:
- Start > Type
optionalfeatures
(this is the quickest way to get to the "Turn Windows Features on or off" window) - Navigate to Internet Information Services > World Wide Web Services > Performance Features in the "Windows Features" treeview
- Ensure "Dynamic Content Compression" is ticked
- Click "Ok" and wait whilst Windows installs the component
这篇关于在 IIS7 上使用 MVC3 时如何启用 gzip 压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!