IIS 中的 GZIP CSS 和 Javascript 文件

发布于 2024-11-10 04:54:22 字数 969 浏览 4 评论 0原文

我正在尝试将压缩后的内容传递给浏览器使用 Coldfusion 压缩我的 javascript 文件的版本。

我尝试将以下内容添加到 web.config 但仍然没有显示 GZIP (使用 Fiddler)

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
    <dynamicTypes>
      <add mimeType="text/*" enabled="true"/>
      <add mimeType="message/*" enabled="true"/>
      <add mimeType="application/javascript" enabled="true"/>
      <add mimeType="*/*" enabled="false"/>
    </dynamicTypes>
    <staticTypes>
      <add mimeType="text/*" enabled="true"/>
      <add mimeType="message/*" enabled="true"/>
      <add mimeType="application/javascript" enabled="true"/>
      <add mimeType="*/*" enabled="false"/>
    </staticTypes>
  </httpCompression>
  <urlCompression doStaticCompression="true" doDynamicCompression="true"/>

I'm trying to deliver to the browser the Compressed & Gzipped version of my javascript files using coldfusion.

I've tried to add the following to the web.config but still not showing GZIP (using Fiddler)

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
    <dynamicTypes>
      <add mimeType="text/*" enabled="true"/>
      <add mimeType="message/*" enabled="true"/>
      <add mimeType="application/javascript" enabled="true"/>
      <add mimeType="*/*" enabled="false"/>
    </dynamicTypes>
    <staticTypes>
      <add mimeType="text/*" enabled="true"/>
      <add mimeType="message/*" enabled="true"/>
      <add mimeType="application/javascript" enabled="true"/>
      <add mimeType="*/*" enabled="false"/>
    </staticTypes>
  </httpCompression>
  <urlCompression doStaticCompression="true" doDynamicCompression="true"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情绪失控 2024-11-17 04:54:22

我通过在 IIS 角色服务下安装动态压缩解决了我的问题,现在它就像一个魅力。

I solved my problem by installing dynamic compression under IIS Roles Services and now it works like a charm.

傲世九天 2024-11-17 04:54:22

在 IIS 中启用压缩后,无需预压缩 .js 文件。服务器将管理压缩、检查浏览器支持并在支持时发送压缩文件,而无需您做任何工作。

您只需要将 js 文件放在服务器上就可以了。只需使用 src 中的普通文件名作为脚本标记,服务器将管理其余的所有内容。由于它不是 ColdFusion 文件,ColdFusion 服务器永远不会接触它。

With compression on in IIS there is no need to pre-compress the .js files. The server will manage compressing, checking for browser support and sending the compressed file when it is supported without you doing any work on your end.

You just need to put the js file on the server and you should be good to go. Just use the normal file name in the src for the script tag and the server will manage all of the rest of it. Since it is not a ColdFusion file the ColdFusion server doesn't ever touch it.

魂归处 2024-11-17 04:54:22

浏览器不是只是解压缩它,就像它应该的那样,然后您就看到了最终结果。
您还可以使用 cfhttp 访问相同的 url,并查看它返回的内容。这样,您可以轻松控制和查看压缩或未压缩的内容。

Isn't the browser just uncompressing it, like it should, and your seeing the the end result.
You could also use cfhttp to hit the same url, and see what it returns. With that, you can easily control and see what is compressed or uncompresed.

抹茶夏天i‖ 2024-11-17 04:54:22

仅使用 IIS 中的压缩选项,并直接链接到 JS / CSS 文件,不要通过 ColdFusion 提供它们。

浏览器窗口中的内容已被缩小,而不是压缩。

浏览器能够识别压缩内容;浏览器将告诉服务器它们可以处理哪些格式(如果有)。压缩后的js文件在你看到之前会被浏览器自动解压。这就是为什么看到的内容是纯文本。

至于 YSlow,请确保它不会抱怨未压缩的 CSS 文件。

Only use the compression option in IIS, and directly link to the JS / CSS files, don't serve them via ColdFusion.

The content in your browser window has been minified, not compressed.

Browsers are aware of compressed content; the browser will tell the server what formats (if any) that they can handle. The compressed js file is automatically decompressed by the browser before you see it. This is why the content is see is plain text.

As for YSlow, make sure it is not complaining about uncompressed CSS files.

萌酱 2024-11-17 04:54:22

您似乎已指定 MIME 类型 "application/x-javascript" 应由 IIS 压缩。但是,您将从 ColdFusion 返回 MIME 类型 "application/javascript"

It looks like you've specified that the MIME type "application/x-javascript" should be compressed by IIS. However, you are returning the MIME type "application/javascript" from ColdFusion.

意犹 2024-11-17 04:54:22

对于CSS压缩也许你们应该尝试这个属性;

<add mimeType="text/css" enabled="true"/>

及其整个代码(包括利用浏览器缓存);

<system.webServer>
<httpCompression directory="C:\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="C:\Windows\System32\inetsrv\gzip.dll"/>
<dynamicTypes>
  <add mimeType="text/*" enabled="true"/>
  <add mimeType="message/*" enabled="true"/>
  <add mimeType="application/javascript" enabled="true"/>
  <add mimeType="*/*" enabled="false"/>
  <add mimeType="text/css" enabled="true"/>
</dynamicTypes>
<staticTypes>
  <add mimeType="text/*" enabled="true"/>
  <add mimeType="message/*" enabled="true"/>
  <add mimeType="application/javascript" enabled="true"/>

  <add mimeType="*/*" enabled="false"/>
  </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
</staticContent>
</system.webServer>

for css compression maybe you guys should try this attribute;

<add mimeType="text/css" enabled="true"/>

and its the entire code(leverage browser caching includes);

<system.webServer>
<httpCompression directory="C:\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="C:\Windows\System32\inetsrv\gzip.dll"/>
<dynamicTypes>
  <add mimeType="text/*" enabled="true"/>
  <add mimeType="message/*" enabled="true"/>
  <add mimeType="application/javascript" enabled="true"/>
  <add mimeType="*/*" enabled="false"/>
  <add mimeType="text/css" enabled="true"/>
</dynamicTypes>
<staticTypes>
  <add mimeType="text/*" enabled="true"/>
  <add mimeType="message/*" enabled="true"/>
  <add mimeType="application/javascript" enabled="true"/>

  <add mimeType="*/*" enabled="false"/>
  </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
</staticContent>
</system.webServer>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文