Skip to content

Commit 7a1c3f7

Browse files
author
dhp94d
committed
feat: 렌더링 차단 리소스 제거
1 parent 43cd18c commit 7a1c3f7

File tree

2 files changed

+174
-47
lines changed

2 files changed

+174
-47
lines changed

README.md

+44-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
- [2.3.2 aspect-ratio 적용](#232-aspect-ratio-적용)
2020
- [2.3.3 이미지 크기 최적화](#233-이미지-크기-최적화)
2121
- [2.3.4 이미지 lazy-load 적용](#234-이미지-lazy-load-적용)
22-
- [2.3.5 개선 결과](#235-개선-결과)
22+
- [2.3.5 개선 결과](#235-개선-결과)
23+
- [2.4 렌더링 차단 리소스 제거하기](#24-렌더링-차단-리소스-제거하기)
2324

2425
---
2526

@@ -94,6 +95,8 @@ requestIdleCallback(heavyOperationAsync, { timeout: 3000 });
9495
main.js 코드 365 -> 275
9596
products.js 코드 2319 -> 1223
9697

98+
---
99+
97100
#### 2.1.3 개선 결과
98101

99102
위 두 과정을 통해서 어떤 변화가 일어났는지 확인해보겠습니다.
@@ -108,6 +111,8 @@ products.js 코드 2319 -> 1223
108111
**자바스크립트 실행 시간 단축 후기**
109112
해당 프로젝트는 매우 간단한 프로젝트로 아주 간단한 기술들만 적용이 되었는데요, 만약 큰 프로젝트를 진행하시고 계시다면 트리쉐이킹, 망글링, 코드분할, 레이지로딩 등 다양한 기술들을 적용해보시면 됩니다!
110113

114+
---
115+
111116
### 2.2 차세대 형식을 사용해 이미지 제공하기
112117

113118
#### 2.2.1 이미지 변환 jgp -> avif
@@ -120,6 +125,8 @@ products.js 코드 2319 -> 1223
120125
<img width="799" alt="image" src="https://github.com/user-attachments/assets/f783f4c1-ea4f-4701-922b-e516f72d5428">
121126
<br/>
122127

128+
---
129+
123130
#### 2.2.2 개선 결과
124131

125132
이제 결과를 확인해봅니다!!
@@ -134,7 +141,9 @@ products.js 코드 2319 -> 1223
134141
3. ssr환경으로 서버에서 avif로 변환하여 저장 -> 현재불가능
135142
4. 클라이언트에서 avif로 변환 -> 가능
136143

137-
4번의 경우 가능하지만.. 추천하지 않음 오히려 제네레이터 과정에서 오히려 렌더링시간이 더 늘어날 수 있음.. 더불어 이미 브라우저가 jpg파일을 받은 상태로 이미지 렌더링시 일부 성능 향상을 얻을수는 있지만 효과가 크리티컬하지않아, 다른 이미지 최적화 용법을 통해 최적화 하는것용이하기 때문에 **차세대 형식을 사용해 이미지 제공하기** 최적화는 여기까지만 진행하겠습니다! 현업에서는 꼭 1,2,3을 활용해주세요!
144+
&nbsp;4번의 경우 가능하지만.. 추천하지 않음 오히려 제네레이터 과정에서 오히려 렌더링시간이 더 늘어날 수 있음.. 더불어 이미 브라우저가 jpg파일을 받은 상태로 이미지 렌더링시 일부 성능 향상을 얻을수는 있지만 효과가 크리티컬하지않아, 다른 이미지 최적화 용법을 통해 최적화 하는것용이하기 때문에 **차세대 형식을 사용해 이미지 제공하기** 최적화는 여기까지만 진행하겠습니다! 현업에서는 꼭 1,2,3을 활용해주세요!
145+
146+
---
138147

139148
### 2.3 이미지 크기 적절하게 설정하기 & 이미지 요소에 width 및 height 명시하기
140149

@@ -181,6 +190,8 @@ source는 우선, media를 통해 source를 필터하고 그 후 type조건을
181190
<br/>
182191
<br/>
183192

193+
---
194+
184195
#### 2.3.2 aspect-ratio 적용
185196

186197
&nbsp;다음은 반응형으로 영역을 잡아 사용하는 img를 레이아웃 시프트가 되지 않도록 초기영역을 지정해주겠습니다. 현재 img영역은 아래와 같습니다
@@ -245,6 +256,8 @@ section.best-sellers .product-slider .product img {
245256

246257
레이아웃 시프트가 확연히 개선되었습니다!!
247258

259+
---
260+
248261
#### 2.3.3 이미지 크기 최적화
249262

250263
현재 렌더링되는 화면에 비해 사이가 과도하게 큰 이미지들이 있습니다. 이를 최적화된 크기로 자르고 압축하여 사이즈를 최적화 해봅시다.
@@ -257,7 +270,7 @@ avif로 변환을 하였으나, 여전히 큰 사이즈들이 있습니다. 이
257270

258271
1. 이미지 사이즈 조정(렌더링 및 fixed된 size에 맞게 크기 조정)
259272
2. 이미지 압축(그래픽이 크게 손상되지 않는 수준에서 최대한 압축)
260-
3. jpg -> avif, webp 변환
273+
3. ## jpg -> avif, webp 변환
261274

262275
#### 2.3.4 이미지 lazy-load 적용
263276

@@ -303,11 +316,38 @@ observer.observe(img);
303316
해당 코드를 통해 이전과 다르게 사이트에 접속 시 뷰포트에 있는 이미지만 로드하는것을 보실 수 있습니다.
304317
![image](https://github.com/user-attachments/assets/3d70ee4f-1ca0-4762-9f8a-fac2b479941f)
305318

306-
#### 2.3.5 개선 결과
319+
---
320+
321+
#### 2.3.5 개선 결과
307322

308323
자 이제 얼마나 개선되었는지 지표를 확인해볼까요?
309324
![image](https://github.com/user-attachments/assets/f4ca7ca8-6134-437b-b756-ee68e8f715c1)
310325
![image](https://github.com/user-attachments/assets/6e6ad395-702d-4b66-a84d-6ed30230b02a)
311326
![image](https://github.com/user-attachments/assets/0be71f54-e2fa-44ae-bfc7-14397ac5d495)
312327

313328
이미지 관련된 지표가 모두 정상화 되었습니다!! 짝짝짝짝
329+
330+
---
331+
332+
### 2.4 렌더링 차단 리소스 제거하기
333+
334+
<img width="776" alt="image" src="https://github.com/user-attachments/assets/3e928ab4-40a0-4206-8755-80f4e3aabe0c">
335+
cookie-consent.js가 LCP와 FCP를 방해하고 있다고 설명되어 있는데요, cookie-consent.js를 어떻게 호출하고있나 확인해보겠습니다.
336+
337+
<br/>
338+
<br/>
339+
340+
```
341+
<head>
342+
<!-- Cookie Consent by FreePrivacyPolicy.com https://www.FreePrivacyPolicy.com -->
343+
<script
344+
type="text/javascript"
345+
src="//www.freeprivacypolicy.com/public/cookie-consent/4.1.0/cookie-consent.js"
346+
charset="UTF-8"
347+
></script>
348+
</head>
349+
```
350+
351+
&nbsp;해당 이슈를 해결하기 위해서는 \<head> 태그에 대한 이해가 있어야 합니다.
352+
353+
&nbsp;현재 구조에서의 문제점은

index.html

+130-43
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,28 @@
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Home - Tech Shop</title>
8-
<link href="https://fonts.googleapis.com/css?family=Heebo:300,400,600,700&display=swap" rel="stylesheet" />
8+
<link
9+
href="https://fonts.googleapis.com/css?family=Heebo:300,400,600,700&display=swap"
10+
rel="stylesheet"
11+
/>
912
<link rel="stylesheet" href="/css/styles.css" />
1013
<!-- <link rel="stylesheet" type="text/css" href="/css/slick.css"/> -->
11-
<!-- Google Tag Manager -->
12-
<script>
13-
(function (w, d, s, l, i) {
14-
w[l] = w[l] || [];
15-
w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
16-
var f = d.getElementsByTagName(s)[0],
17-
j = d.createElement(s),
18-
dl = l != 'dataLayer' ? '&l=' + l : '';
19-
j.async = true;
20-
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
21-
f.parentNode.insertBefore(j, f);
22-
})(window, document, 'script', 'dataLayer', 'GTM-PKK35GL5');
23-
</script>
14+
2415
<!-- End Google Tag Manager -->
2516

2617
<!-- Cookie Consent by FreePrivacyPolicy.com https://www.FreePrivacyPolicy.com -->
27-
<script type="text/javascript" src="//www.freeprivacypolicy.com/public/cookie-consent/4.1.0/cookie-consent.js" charset="UTF-8"></script>
28-
<script type="text/javascript" charset="UTF-8">
29-
cookieconsent.run({
30-
notice_banner_type: 'simple',
31-
consent_type: 'express',
32-
palette: 'light',
33-
language: 'en',
34-
page_load_consent_levels: ['strictly-necessary'],
35-
notice_banner_reject_button_hide: false,
36-
preferences_center_close_button_hide: false,
37-
page_refresh_confirmation_buttons: false,
38-
website_name: 'Performance Course',
39-
});
40-
</script>
4118
</head>
4219

4320
<body>
4421
<!-- Google Tag Manager (noscript) -->
45-
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PKK35GL5" height="0" width="0" style="display: none; visibility: hidden"></iframe></noscript>
22+
<noscript
23+
><iframe
24+
src="https://www.googletagmanager.com/ns.html?id=GTM-PKK35GL5"
25+
height="0"
26+
width="0"
27+
style="display: none; visibility: hidden"
28+
></iframe
29+
></noscript>
4630
<!-- End Google Tag Manager (noscript) -->
4731

4832
<header>
@@ -60,32 +44,88 @@
6044
<li><a href="about.html">About us</a></li>
6145
<li><a href="index.html#best-sellers-section">Best Sellers</a></li>
6246
<li><a href="index.html#newsletter-section">Newsletter</a></li>
63-
<li class="menu-icon"><img src="images/menu_icon.webp" width="24" height="17" /></li>
47+
<li class="menu-icon">
48+
<img src="images/menu_icon.webp" width="24" height="17" />
49+
</li>
6450
</ul>
6551
</nav>
6652
</div>
6753
</header>
6854

6955
<section class="hero">
7056
<picture>
71-
<source width="576" height="576" media="(max-width: 575px)" srcset="images/Hero_Mobile.avif" type="image/avif" />
72-
<source width="960" height="770" media="(min-width: 576px) and (max-width: 960px)" srcset="images/Hero_Tablet.avif" type="image/avif" />
73-
<source width="1920" height="893" srcset="images/Hero_Desktop.avif" type="image/avif" />
57+
<source
58+
width="576"
59+
height="576"
60+
media="(max-width: 575px)"
61+
srcset="images/Hero_Mobile.avif"
62+
type="image/avif"
63+
/>
64+
<source
65+
width="960"
66+
height="770"
67+
media="(min-width: 576px) and (max-width: 960px)"
68+
srcset="images/Hero_Tablet.avif"
69+
type="image/avif"
70+
/>
71+
<source
72+
width="1920"
73+
height="893"
74+
srcset="images/Hero_Desktop.avif"
75+
type="image/avif"
76+
/>
7477

75-
<source width="576" height="576" media="(max-width: 575px)" srcset="images/Hero_Mobile.webp" type="image/webp" />
76-
<source width="960" height="770" media="(min-width: 576px) and (max-width: 960px)" srcset="images/Hero_Tablet.webp" type="image/webp" />
77-
<source width="1920" height="893" srcset="images/Hero_Desktop.webp" type="image/webp" />
78+
<source
79+
width="576"
80+
height="576"
81+
media="(max-width: 575px)"
82+
srcset="images/Hero_Mobile.webp"
83+
type="image/webp"
84+
/>
85+
<source
86+
width="960"
87+
height="770"
88+
media="(min-width: 576px) and (max-width: 960px)"
89+
srcset="images/Hero_Tablet.webp"
90+
type="image/webp"
91+
/>
92+
<source
93+
width="1920"
94+
height="893"
95+
srcset="images/Hero_Desktop.webp"
96+
type="image/webp"
97+
/>
7898

79-
<source width="576" height="576" media="(max-width: 575px)" srcset="images/Hero_Mobile.jpg" type="image/jpg" />
80-
<source width="960" height="770" media="(min-width: 576px) and (max-width: 960px)" srcset="images/Hero_Tablet.jpg" type="image/jpg" />
81-
<source width="1920" height="893" srcset="images/Hero_Desktop.jpg" type="image/jpg" />
99+
<source
100+
width="576"
101+
height="576"
102+
media="(max-width: 575px)"
103+
srcset="images/Hero_Mobile.jpg"
104+
type="image/jpg"
105+
/>
106+
<source
107+
width="960"
108+
height="770"
109+
media="(min-width: 576px) and (max-width: 960px)"
110+
srcset="images/Hero_Tablet.jpg"
111+
type="image/jpg"
112+
/>
113+
<source
114+
width="1920"
115+
height="893"
116+
srcset="images/Hero_Desktop.jpg"
117+
type="image/jpg"
118+
/>
82119
<img width="1920" height="893" src="images/Hero_Desktop.jpg" />
83120
</picture>
84121

85122
<div class="hero-content">
86123
<div class="container">
87124
<h1>Discover our line of VR Headsets</h1>
88-
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</p>
125+
<p>
126+
Sed ut perspiciatis unde omnis iste natus error sit voluptatem
127+
accusantium doloremque laudantium.
128+
</p>
89129
<button>View Headsets</button>
90130
</div>
91131
</div>
@@ -100,7 +140,12 @@ <h1>Best Sellers</h1>
100140
<div class="container">
101141
<div class="product new">
102142
<div class="product-picture">
103-
<img src="images/vr1.avif" width="350px" height="350px" alt="product: Penom Case" />
143+
<img
144+
src="images/vr1.avif"
145+
width="350px"
146+
height="350px"
147+
alt="product: Penom Case"
148+
/>
104149
</div>
105150
<div class="product-info">
106151
<h5 class="categories">Headsets, Apple</h5>
@@ -114,7 +159,12 @@ <h3 class="price">
114159

115160
<div class="product new">
116161
<div class="product-picture">
117-
<img src="images/vr2.avif" width="350px" height="350px" alt="product: Noise Cancelling Headphone" />
162+
<img
163+
src="images/vr2.avif"
164+
width="350px"
165+
height="350px"
166+
alt="product: Noise Cancelling Headphone"
167+
/>
118168
</div>
119169
<div class="product-info">
120170
<h5 class="categories">Headsets, PS</h5>
@@ -128,7 +178,12 @@ <h3 class="price">
128178

129179
<div class="product">
130180
<div class="product-picture">
131-
<img src="images/vr3.avif" width="350px" height="350px" alt="product: Canon Digital SLR EOS Rebel T6" />
181+
<img
182+
src="images/vr3.avif"
183+
width="350px"
184+
height="350px"
185+
alt="product: Canon Digital SLR EOS Rebel T6"
186+
/>
132187
</div>
133188
<div class="product-info">
134189
<h5 class="categories">Headsets, Oculus</h5>
@@ -208,5 +263,37 @@ <h3>Newsletter Signup</h3>
208263

209264
<script type="text/javascript" src="/js/main.min.js"></script>
210265
<script type="text/javascript" src="/js/products.min.js"></script>
266+
<!-- Google Tag Manager -->
267+
<script>
268+
(function (w, d, s, l, i) {
269+
w[l] = w[l] || [];
270+
w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
271+
var f = d.getElementsByTagName(s)[0],
272+
j = d.createElement(s),
273+
dl = l != 'dataLayer' ? '&l=' + l : '';
274+
j.async = true;
275+
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
276+
f.parentNode.insertBefore(j, f);
277+
})(window, document, 'script', 'dataLayer', 'GTM-PKK35GL5');
278+
</script>
279+
<script
280+
type="text/javascript"
281+
src="//www.freeprivacypolicy.com/public/cookie-consent/4.1.0/cookie-consent.js"
282+
charset="UTF-8"
283+
defer
284+
></script>
285+
<script type="text/javascript" charset="UTF-8" defer>
286+
cookieconsent.run({
287+
notice_banner_type: 'simple',
288+
consent_type: 'express',
289+
palette: 'light',
290+
language: 'en',
291+
page_load_consent_levels: ['strictly-necessary'],
292+
notice_banner_reject_button_hide: false,
293+
preferences_center_close_button_hide: false,
294+
page_refresh_confirmation_buttons: false,
295+
website_name: 'Performance Course',
296+
});
297+
</script>
211298
</body>
212299
</html>

0 commit comments

Comments
 (0)