我正在测试几种改进和减少响应大小,网络流量和加载时间的方法.我想到的一件事是trimDirectiveWhitespaces元素.我将它放在页面指令中:
<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true"%>
Run Code Online (Sandbox Code Playgroud)
我添加了一些空的新行,并没有看到我的响应有任何变化,或者当我查看文档的来源时,有新行.
这个的正确用法是什么?我做错了什么?
trimDirectiveWhitespaces仅删除JSP标记周围的空行,并保留其他空行.
例:
<% page pageEncoding="UTF-8"%>X
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>X
<html>
<head>
Run Code Online (Sandbox Code Playgroud)
这将成为:
X
X
<html>
<head>
Run Code Online (Sandbox Code Playgroud)
(注意我添加X了标记这个例子的行尾,所以它更明显,stackoverflow不会修剪它们)
如果trimDirectiveWhitespaces="true"添加到page指令中,则输出变为:
<html>
<head>
Run Code Online (Sandbox Code Playgroud)
删除前两个空行,但保留下两个(在html和head标记之间).
您也可以trim-directive-whitespaces在其中放置以下配置:web.xml
<web-app xmlns=...>
(...)
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
(...)
</web-app>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9437 次 |
| 最近记录: |