I am testing several ways to improve and reduce my response size, network traffic, and load time. One of the things I thought of using is the trimDirectiveWhitespaces element. I placed it in the page directive:
<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true"%>
I added some empty new lines and didn't see any change in my response or when i view source of the document, new lines were there.
What is the correct usage of this and what am I doing wrong?
trimDirectiveWhitespaces only removes empty lines around JSP tags and leaves other empty lines as they are.
Example:
<% page pageEncoding="UTF-8"%>X
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>X
<html>
<head>
This will become:
X
X
<html>
<head>
(note I added X
to mark end-of-line for this example, so it is more obvious and stackoverflow wont trim them out)
If trimDirectiveWhitespaces="true"
is added to the page
directive, the output becomes:
<html>
<head>
The first two empty lines are removed, but the next two (between the html
and head
tags) are preserved.
You can place the following configuration for trim-directive-whitespaces
in web.xml
as well:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With