관리 메뉴

웹개발 블로그

[JSP]JSP 공백 코드 제거(HTML 마크업 용량 다이어트) 본문

◆JSP/설정

[JSP]JSP 공백 코드 제거(HTML 마크업 용량 다이어트)

쿠키린 2024. 10. 23. 15:40

방법1. JSP 페이지 상단 적용

<%@page trimDirectiveWhitespaces="true" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

 

방법2. build.gradle 일괄 적용

//JSP파일에서 공백 제거 속성(trimDirectiveWhitespaces) 일괄 적용
task addTrimDirectiveToJsp(type: Copy) {
    from 'src/main/webapp/WEB-INF/jsp' // JSP 파일이 위치한 폴더
    include '**/*.jsp'
    into 'build/processedJsp'

    eachFile { file ->
        def fileContent = file.file.text
        if (!fileContent.contains('trimDirectiveWhitespaces')) {
            def newContent = '<%@ page trimDirectiveWhitespaces="true" %>\n' + fileContent
            file.file.write(newContent)
        }
    }
}

processResources.dependsOn addTrimDirectiveToJsp