怎么有效的提高页面的打开速度,提高网站性能,发现查看网站页面源代码的时候,页面上充斥了无数的空格跟换行,
增加了页面的体积,这样会影响页面性能,为了有效的解决这个问题,现提供方法如下:
1、在工程的web.xml上加上如下配置
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
2、在每个JSP的头上加上一段代码 <%@ page trimDirectiveWhitespaces="true" %>
以上两种方法取其一即可,建议使用第一种。
P.S: web.xml 中的配置需在servlet2.5(tomcat6.0)以上才能用。
web.xml升级为2.5 web-app写法如下:
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
metadata-complete="false"
version="2.5">