스프링부트에서 정적자원 버저닝 방법은 두가지가 있다.

application.properties 파일을 통해서 간단히 설정할 수 있는데 그건 thymeleaf만 해당하는거 같다.. 

나는 jsp를 사용하는데 jsp의 경우는 추가로 bean을 등록해줘야 사용가능하다(이거땜에 3주는 허비한듯)

 

1. application.properties

# 1. ex) /css/spring-2a2d595e6ed9a0b24f027f2b63b134d6.css
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
# 2. ex) /v12/js/lib/mymodule.js
spring.resources.chain.strategy.fixed.enabled=true
spring.resources.chain.strategy.fixed.version=v12
spring.resources.chain.strategy.fixed.paths=/**

2-1. jsp (jstl)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="<c:url value='/static/images/test.css'/>"></link>
<link rel="stylesheet" type="text/css" href="<spring:url value='/static/images/test.css'/>"></link>
</head>
<body>
	<h2>static resources caching test</h2>
	<input type="text" value="${message}">
</body>
</html>

2-2.html (thymeleaf)

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" th:href="@{/static/images/test.css}"></link>
</head>
<body>
	<h2>test html</h2>
	<span th:text="${message}"></span>
</body>
</html>

 

3. bean 등록( thymeleaf의 경우 생략 해도 동작 가능 확인)

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;

@Configuration
public class WebConfig{
	
	@Bean
    public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
        return new ResourceUrlEncodingFilter();
    } 

}

 

결과

1번 설정

 

2번 설정

 

 

 

 

 

 

 

 

Posted by 건강코더 트랙백 0 : 댓글 0

댓글을 달아 주세요