본문 바로가기

Script

JS, CSS에 타임스탬프 적용하는 방법

1. 이유

블로그를 운영하면서 CSS, JS 파일을 자주 업로드 및 갱신하여 테스트시 바로 적용되는 것을 확인

 

2. 적용방법


$(function(){
	var t=new Date().getTime();

	$("head").append("<link rel='stylesheet' href='./test_style_a.css?v="+ t +"'>"),

	$("<link/>", { rel: "stylesheet", type: "text/css", href: "./test_style_b.css?v=" + t }).appendTo('head'),

	$("body").append("<script defer src='./test_script_a.js?v="+ t +"'>"),

	$.getScript("./test_script_b.js?v=" + t, function() { autoWrap("__tidory", ".body"); }),
	$.getScript("./test_script_c.js?v=" + t);

	});

 

3. 결과 값 ?

<link rel="stylesheet" type="text/css" href="https://test_style_a.css?v=1634201665581">

<script src="https://test_script_a.js?v=1634201665581"></script>