gpt4 book ai didi

jetty - 如何在 Jetty 中启用 gzip 压缩?

转载 作者:行者123 更新时间:2023-12-05 06:44:47 25 4
gpt4 key购买 nike

我想知道如何为 broadleaf 中的静态文件(js、css、html 和图像)启用 gzip 压缩。我在项目的 web.xml 文件中尝试了以下内容,并且我还获得了与 org.eclipse.jetty.servlets.GzipFilter< 相对应的依赖项类:

<filter>
<filter-name>GzipFilter</filter-name>
<filter-class> org.eclipse.jetty.servlets.GzipFilter</filter-class>
<init-param>
<param-name>mimeTypes</param-name>
<param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>GzipFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

我在 Stack Overflow 上看到的问题没有给我答案,所以我要发布一个新问题。在我的项目中,我有一个像这样的 jetty-web.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<Set name="contextPath">/</Set>

</Configure>

当我尝试在 jetty-web.xml 文件中添加 过滤器映射 时,我收到一个错误,提示它不熟悉 过滤标签。

我应该在 HTML/JS/CSS 文件中添加/修改什么吗?

最佳答案

webdefault.xml中使用init-param:

<init-param>
<param-name>gzip</param-name>
<param-value>true</param-value>
</init-param>

或将处理程序添加到 jetty.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<!-- =============================================================== -->
<!-- Mixin the GZIP Handler -->
<!-- This applies the GZIP Handler to the entire server -->
<!-- If a GZIP handler is required for an individual context, then -->
<!-- use a context XML (see test.xml example in distribution) -->
<!-- =============================================================== -->

<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="insertHandler">
<Arg>
<New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
<Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>
<Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set>
<Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/></Set>
<Set name="inflateBufferSize"><Property name="jetty.gzip.inflateBufferSize" default="0"/></Set>
<Set name="syncFlush"><Property name="jetty.gzip.syncFlush" default="false" /></Set>

<Set name="excludedAgentPatterns">
<Array type="String">
<Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
</Array>
</Set>

<Set name="includedMethodList"><Property name="jetty.gzip.includedMethodList" default="GET" /></Set>
<Set name="excludedMethodList"><Property name="jetty.gzip.excludedMethodList" default="" /></Set>

<!--
<Set name="includedMethods">
<Array type="String">
<Item>GET</Item>
</Array>
</Set>
<Set name="includedPaths">
<Array type="String">
<Item>/*</Item>
</Array>
</Set>
<Set name="excludedPaths">
<Array type="String">
<Item>*.gz</Item>
</Array>
</Set>
<Call name="addIncludedMimeTypes">
<Arg><Array type="String">
<Item>some/type</Item>
</Array></Arg>
</Call>
<Call name="addExcludedMimeTypes">
<Arg><Array type="String">
<Item>some/type</Item>
</Array></Arg>
</Call>
-->

</New>
</Arg>
</Call>
</Configure>

引用资料

关于jetty - 如何在 Jetty 中启用 gzip 压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27512402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com