-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from Docent-Inc/feature/리소스최적화
Feature/리소스최적화 - 리소스 로딩 속도 최적화
- Loading branch information
Showing
5 changed files
with
125 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* directives.ts | ||
* 커스텀 디렉티브 | ||
*/ | ||
|
||
// v-lazyload (참고: https://url.kr/l5bxa1) | ||
const lazyloadDirective = { | ||
mounted(el, binding) { | ||
function loadImage(targetElement, imageUrl) { | ||
const imgElement = targetElement; | ||
imgElement.setAttribute("src", imageUrl); | ||
} | ||
|
||
function callIntersectionApi() { | ||
const options = { | ||
root: null, | ||
threshold: 0.5, | ||
rootMargin: "0px", | ||
}; | ||
|
||
const callback = (entries, observer) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting) { | ||
loadImage(entry.target, binding.value); | ||
observer.unobserve(entry.target); | ||
} | ||
}); | ||
}; | ||
|
||
const lazyLoadingIO = new IntersectionObserver(callback, options); | ||
lazyLoadingIO.observe(el); | ||
} | ||
|
||
// 지원하는 경우에만 Observe | ||
window.IntersectionObserver ? callIntersectionApi() : loadImage(el); | ||
}, | ||
}; | ||
|
||
export default defineNuxtPlugin((nuxtApp) => { | ||
nuxtApp.vueApp.directive("lazyload", lazyloadDirective); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters